class Drawing: """Class for displaying rectangles, squares and circles. Note that origin is upper-LEFT with y positive DOWNWARDS.""" def __init__(self, width, height): try: import Tkinter except ImportError: import tkinter as Tkinter self.app = Tkinter.Frame() self.app.grid(sticky="nsew") self.canvas = Tkinter.Canvas(self.app, width=width, height=height) self.canvas.grid(row=0, column=0, sticky="nsew") def add_rectangle(self, llx, lly, urx, ury, color): self.canvas.create_rectangle((llx, lly, urx, ury), fill=color) def add_circle(self, llx, lly, urx, ury, color): self.canvas.create_oval((llx, lly, urx, ury), fill=color) def run(self): self.app.mainloop() if __name__ == "__main__": # Some simple test code. d = Drawing(100, 100) d.add_circle(25, 25, 75, 75, "red") d.run() # The "real" testing code should be much more elaborate than this # of course. The code here: # (a) does not test the entire API (add_rectangle is not # used), and # (b) does not test each method with different data (only # one good input is used; boundary conditions # and error inputs are not tested). # A good way for constructing test code is to use the standard # Python "unittest" module.