TKinter Drawing

If you are going to draw in Tkinter you’ll need a canvas.  The following code sets you up with a basic window and canvas in Python 3.4

Once you have a canvas you can start to think about how you might draw on it. Of course you might want to include images, animated Gifs or just draw straight onto the canvas. Once you have drawn objects onto the Canvas you can manipuate and interact with them using the Canvas Methods. The following images show my planning, complete code and the resulting window.  

[album id=4 view=gallery]

There are a number of shapes that you can draw directly onto the canvas such as:

Rectangles and Squares

Ovals and Circles

Lines

Polygons

Drawing a polygon is slightly different to a line or eclipse in that it has more than just two sets of x/y coordinates.

Arcs

Drawing an arc gives you three options: ARC, PIESLICE or CHORD. An arc is shown below with a cord being joined across its points and a pieslice which connects via the centre.

Bitmaps

Bitmaps can be used to draw two colour images.  

About CDB 360 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.