# CSE 142 Python # # This file provides a simplified version of the DrawingPanel # functionality to match our Java DrawingPanel. # # It is implemented using Python's built-in Tkinter graphics package. # Place it in the same directory as your Python programs. # from Tkinter import * import time class DrawingPanel(Frame): def __init__(self, w=500, h=500, master=None): Frame.__init__(self, master) self.master.title("DrawingPanel") self.pack() self.canvas = Canvas(self, width=w, height=h) self.canvas["bg"] = "white" self.canvas.pack({"side": "right"}) self.update() def get_graphics(self): return self.canvas def set_background(self, color): self.canvas["bg"] = color def sleep(self, ms): try: self.update() time.sleep(ms / 1000.0) self.update() except Exception: pass