from Tkinter import * import time class DrawingPanel(Frame): """A Tkinter wrapper object aimed at mimicking the Java DrawingPanel.""" def __init__(self, w=500, h=500, master=None): """Create a window with height h and width w and parent window master.""" Frame.__init__(self, master) self.pack() self.canvas = Canvas(self, width=w, height=h) self.canvas["bg"] = "white" self.canvas.pack({"side": "right"}) self.update() def getGraphics(self): """Get the Graphics object equivalent.""" return self.canvas def setBackground(self, color): """Set the background color of the window.""" self.canvas["bg"] = color def show(self): """Show the window. Note: this will block such that the code after this call will not be called until the window is closed.""" self.mainloop() def sleep(self, ms): """Pause the code for ms milliseconds.""" self.update() time.sleep(ms / 1000.0) self.update()