The Complete Shapes and DrawShapes Modules

We've covered all of the classes. At this point, you may want to run the Shapes and DrawShapes modules to see the drawing package in action. Here's the Shapes module.

 class Shape: def __init__(self, x, y, width=0, height=0, color=None, fill=0): self.x=x self.y=y self.width=width self.height=height self.color=color self.fill=fill def paint(self, graphics): if not self.color is None: oldcolor = graphics.foregroundColor graphics.color = self.color if self.fill: self.draw_filled(graphics) else: self.draw_outline(graphics) if not self.color is None: graphics.color = oldcolor def draw_filled(self, graphics): pass def draw_outline(self, graphics): pass def getRect(self): return self.x, self.y, self.width, ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.