We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Window

Let's just get a graphical window up and running. When we run our code, it should open a new window with a blank canvas that our program can then draw on.

Assignment

  1. You can organize your Python files however you like, though you'll probably want a main.py file for your main function.

  2. from tkinter import Tk, BOTH, Canvas
    
    • Note: Tkinter is not a reactive framework like React or Vue – we need to tell it when to redraw the window.
    • Use the root widget's update_idletasks and update methods to accomplish this.
  3. self.__root = Tk()
    ...
    self.__root.protocol("WM_DELETE_WINDOW", self.close)
    
  4. win = Window(800, 600)
    win.wait_for_close()
    
  5. # Assuming your entrypoint file is main.py
    python3 main.py