O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Canvas widget

The Canvas widget is Tkinter's primary widget for displaying graphics. With a vast range of built-in functions for creating graphics manually, it is the perfect choice for the display piece of a computer game.

Let's have a quick introduction to the Canvas widget's built-in drawing capabilities. Open up a new file and type in the following:

import tkinter as tkwindow = tk.Tk()canvas = tk.Canvas(window, bg="white", width=300, height=300)canvas.pack()canvas.create_oval((0, 0, 300, 300), fill="yellow")canvas.create_arc((50, 100, 100, 150), extent=180, fill="black")canvas.create_arc((200, 100, 250, 150), extent=180, fill="black")canvas.create_line((50, 200, 110, 240), fill="red", width=5)canvas.create_line((110, 240, 190, 240), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required