By Ayesha Rascoe and Ernest Scheyder
WARSAW/DALLAS (Reuters) - President Barack Obama urged Americans on Saturday not to view the United States as being riven into opposing groups, seeking to soothe raw emotions after a former U.S. soldier killed five policemen in Dallas and high-profile police shootings of two black men in Minnesota and Louisiana.
"First of all, as painful as this week has been, I firmly believe that America is not as divided as some have suggested," Obama, visiting Poland, told a news conference in Warsaw.
"When we start suggesting that somehow there's this enormous polarization, and we're back to the situation in the '60s, that's just not true," Obama added. "You're not seeing riots, and you're not seeing police going after people who are protesting peacefully."
Dallas remained on edge on Saturday. The city's police headquarters and surrounding blocks were under lockdown and SWAT teams were deployed after police said they received an anonymous threat against officers across the city.
The police department said it was taking extra safety precautions. Police teams were sweeping a large parking garage at the headquarters building, according to a Reuters eyewitness.
Authorities have named former U.S. Army Reserve soldier Micah Johnson, a 25-year-old African-American, as the lone gunman in Thursday night's sniper attack in Dallas, which came at the end of a march by hundreds of demonstrations decrying the fatal shootings by police of black men earlier in the week.
Officials said Johnson had embraced militant black nationalism and expressed anger over shootings by police as well as a desire to "kill white people, especially white officers."
The rally in Dallas followed the fatal police shootings of Philando Castile, 32, near St. Paul, Minnesota, on Wednesday, and Alton Sterling, 37, in Baton Rouge, Louisiana, on Tuesday.
Obama, who is cutting short his European trip on Sunday to visit Dallas, said that "Americans of all races and all backgrounds are rightly outraged by the inexcusable attacks on police, whether it's in Dallas or any place else."
He added they also are rightly saddened and angered about the deaths of Sterling and Castile, and about "the larger, persistent problem of African-Americans and Latinos being treated differently in our criminal justice system."
Obama, the first black U.S. president whose term in office ends next January, said he hopes he has been able to get all Americans to understand the nation's difficult legacy of race.
Obama said Americans cannot let the actions of a few define all.
"The demented individual who carried out those attacks in Dallas -- he's no more representative of African-Americans than the shooter in Charleston was representative of white Americans, or the shooter in Orlando or San Bernardino were representative of Muslim-Americans," Obama added, referring to a string of mass shootings in the past year.
Seven other police officers and two civilians also were wounded in Dallas. Johnson was killed by a bomb-carrying robot deployed against him in a parking garage where he had holed up and refused to surrender during hours of negotiations with police, authorities said on Friday.
Obama, who has been blocked by the Republican-led U.S. Congress in his bid for new gun-control measures, expressed new frustration over lax firearms laws in the United States, saying it is unique among advanced countries in the scale of violence it experiences.
"With respect to the issue of guns, I am going to keep on talking about the fact that we cannot eliminate all racial tension in our country overnight. We are not going to be able to identify ahead of time and eliminate every madman or troubled individual who might want to do harm against innocent people. But we can make it harder for them to do so," Obama said.
Illustrating the divide among Americans over gun rights, Republican Texas Attorney General Ken Paxton told Reuters that men like the Dallas gunman "are not going to be confined by a gun law that we pass."
Paxton, whose state has among the most permissive gun policies in America, added, "Our goal here in Texas is to protect law-abiding citizens. And since we cannot have a police force that guards every person, we want people to be able to protect themselves."
While Thursday's attack stunned Dallas into mourning, it did not stop demonstrations around the country against killings by police. Hundreds of protesters gathered in Minneapolis on Saturday and other demonstrations were planned for Minnesota, Louisiana, New York and Washington.
Thousands of protesters took to the streets in several cities on Friday, clogging roadways in New York, Atlanta and Philadelphia. Events in San Francisco and Phoenix also drew large crowds.
Early on Saturday, up to 30 protesters were arrested near police headquarters in Baton Rouge, where the FBI has warned of safety concerns for law enforcement and the general public.
Police use of force, particularly against African-Americans, has come under intense scrutiny in the past two years because of a string of high-profile deaths in cities from Ferguson, Missouri, to New York.
Dallas Police Chief David Brown on Friday said the gunman cited his anger over police killings during his protracted negotiations with police after the shootings.
Johnson had served in the U.S. military in the Afghan war. 
A search of his home just outside Dallas found bomb-making materials, ballistic vests, rifles, ammunition and a personal journal of combat tactics, though he had no previous criminal history, police said on Friday.
(Additional reporting by Adam DeRose, Jeff Mason and Arshad Mohammed in Washington, Bryn Stole in Baton Rouge, David Bailey in Minneapolis and Mark Hosenball in London; Writing by Frances Kerry and Will Dunham; Editing by Mary Milliken and Sandra Maler)