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), ...

Get Tkinter GUI Programming by Example 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.