PyDraw: Painting and Moving Graphics
Chapter 10
introduced simple Tkinter animation techniques (see the tour’s
canvasDraw
variants). The PyDraw
program listed here builds upon those ideas to implement a more
feature-rich painting program in Python. It adds new trails and
scribble drawing modes, object and background color fills, embedded
photos, and more. In addition, it implements object movement and
animation techniques—drawn objects may be moved around the canvas by
clicking and dragging, and any drawn object can be gradually moved
across the screen to a target location clicked with the mouse.
Running PyDraw
PyDraw is essentially a Tkinter canvas with lots of keyboard and mouse event bindings to allow users to perform common drawing operations. This isn’t a professional-grade paint program by any definition, but it’s fun to play with. In fact, you really should—it is impossible to capture things such as object motion in the medium afforded by this book. Start PyDraw from the launcher bars (or run the file movingpics.py from Example 12-8 directly). Press the ? key to view a help message giving available commands (or read the help string in the code listings).
Figure 12-13 shows PyDraw after a few objects have been drawn on the canvas. To move any object shown here, either click it with the middle mouse button and drag to move it with the mouse cursor, or middle-click the object, and then right-click in the spot you want it to move toward. In the latter case, PyDraw performs an ...
Get Programming Python, 3rd Edition 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.