A 10-year-old boy took a gun to his school south of Perth earlier this week, police have confirmed.

Police said the boy took the handgun to the Comet Bay Primary School in Secret Harbour to show his friends on Monday.

They said he did not threaten anyone with the weapon, which school staff confiscated.

Police are trying to determine if the weapon is licensed and how the boy got access to it.

An Education Department spokeswoman said the boy took the weapon to his school not realising the gravity of his actions.

She said the school handled the situation extremely well and at no stage were any students in danger.

Comet Bay Primary School principal Matthew Osborne said the school had sent a letter to parents informing them of the incident.

"Earlier this week, one of our students brought a handgun to school," he said.

"I have assured parents that at no time were students threatened. It appears the child brought the item to school to show friends.

"As soon as one of my staff members noticed the handgun it was confiscated and we immediately informed the police.

"Police investigated and asked me to only reveal necessary details to the school community, which I did in the form of a letter to parents.

"A handful of parents have since spoken with me, and they have been reassured by the swift action my staff and I took to ensure student safety."

Mr Osborne said the students who were shown the gun had all received counselling.