President Barack Obama on Saturday rejected any notion that the past week's stunning violence signals a return to racial brutality of a dark past, saying that as painful as the killings of police and black men were, "America is not as divided as some have suggested."

With five Dallas police officers dead at the hands of a sniper and two black men dead at the hands of police, Obama appealed to Americans not to be overwhelmed by fear of a return to 1960s-style chaos and to understand the progress that has been made in racial relations since that time.

"You're not seeing riots and you're not seeing police going after people who are protesting peacefully," he said. "You've seen almost uniformly peaceful protests and you've seen, uniformly, police handling those protests with professionalism."

Obama spoke at the conclusion of a NATO summit in Warsaw before leaving for Spain, part of a farewell trip to Europe he was cutting short by one day because of the developments at home.

The comments marked the third time in as many days that Obama has spoken, from a distance, about the police-involved fatal shootings of black men in Louisiana and Minnesota that were followed by a sniper attack in Dallas that killed five police officers. Seven other officers and two civilians were also injured.

Obama said the Dallas shooter, a black Army veteran who was later killed by police, was a "demented individual" who does not represent black Americans any more than a white man accused of killing blacks at a church in Charleston, South Carolina, represents whites.

The president said he would visit Dallas in a few days to pay respects and mourn with the stricken Texas city. The shootings, and the ensuing protests in some U.S. cities, led to an uncharacteristic response from the president: He cut his five-day, two-country European trip to four days.

Obama proceeded with his plan to visit Madrid but scrapped a stop in the southern city of Seville. He was cramming two days of events into one, including meetings with interim President Mariano Rajoy and a visit with U.S. sailors stationed at a naval base in Rota.

In his news conference before departing Poland, Obama said that while "there is sorrow, there is anger, there is confusion" in the U.S., "there's unity in recognizing that this is not how we want our communities to operate. This is not who we want to be as Americans and that serves as the basis for us being able to move forward in a constructive and positive way."

The president said he planned to convene a White House meeting in coming days with police officers, community and civil rights activists and others to talk about next steps. He said the "empathy and understanding" that Americans have shown in responding to the events of the past few days, including Dallas police officers even as they came under attack, had given him hope.

"That's the spirit that we all need to embrace," Obama said. "That's the spirit that I want to build on."

But Obama, who has angered his political opponents after every deadly mass shooting by calling for tighter gun laws, made clear that he will continue to speak out about the need for such measures, which the Republican-controlled Congress has refused to go along with. He said the U.S. is unique among advanced countries in the scale of violence it experiences.

The president spoke sympathetically of police officers in gun-filled communities who have "very little margin of error" when deciding how to engage with people on the street who may well be armed, whether they mean harm or not. "Police have a really difficult time in communities where they know guns are everywhere," he said.

"If you care about the safety of our police officers, then you can't set aside the gun issue and pretend it's irrelevant."

Citing laws allowing the carrying of guns in Texas, he said that even some of the Dallas protesters who staged a peaceful rally before the sniper attack were armed. He also cited the presence of an apparently legally owned gun in the car where motorist Philando Castile was shot dead during a traffic stop in suburban St. Paul, Minnesota.

Obama also tried to calm public anxiety about personal safety, saying violent crime is actually down in the U.S.

"So as tough, as hard, as depressing as the loss of life was this week, we've got a foundation to build on," he said. "We just have to have confidence that we can build on those better angels of our nature."