Creating the Main Window

Begin your program by telling your code to import the tkinter library. This is a well known python based library for making user interfaces.

from tkinter import *

Creating a gui with tkinter starts with a “root” class. Think of this as the main window, that all of your program will be contained in. You’ll notice that (mostly) every app you use on a computer runs inside of a rectangular box, with some buttons you can use at the top to close or resize it. For the sake of our program, we will call this containing box the “root”. 

root = Tk()

A root window has a function called “geometry” which we can use to set the default size of the program.

root.geometry("500x300")

Whenever we use a program, they also have another function called a mainloop that causes them to “refresh” their screen. In our program, we can call this loop for our root window by using the window’s “mainloop” function. Because this is a loop that will run the bulk of the code in our program, make sure that this line remains the last statement in your program.

#All code in this program should come before this line
root.mainloop()

This is a big project, so there will be a checkpoint halfway through to double check your code. So don’t fret too much if your code doesn’t run how you expect it to.