Saving a screen shot?

Hi there, I am trying to save an screenshot using the following code:

			x = 
			y =
			print str((x, y))
			buffer ='offscreen', x, y)
			img = PNMImage()
			if(img.write(Filename("simulation_"+strftime("%d_%b_%Y_%H:%M:%S", localtime()))) == False):
				print("Error saving file.")

It always prints error, but never tells me what error it is, the x an y are ok (800, 600). Any ideas?

Thanks in advance.

Why not use Showbase’s screenshot function? 8)

Worked perfectly thank you.