Tkinter: Canvas

Create a window with tkinter

This is the code to create a window:

import tkinter as tk

root = tk.Tk()

root.mainloop()

Add a title to the window

root.title("My App")

Dimensions

root.geometry("400x300+100+100")

400×300 = width and height

+100+100 = x, y vertex of the window on the computer screen

Canvas

To add a canvas:

canvas = tk.Canvas(root, width=800, height=400, bg='green')

The bg is the backgroind color.

Advertisement