An overview of basic Tkinter
As exciting as it may be to see that first GUI window pop up on the screen, "Hello World" is not a terribly interesting application. Let's start again and dig a little deeper into Tkinter as we build a slightly larger program. Since the next chapter will see you landing a job at a fictitious agricultural laboratory studying fruit plants, let's create a little program to gauge your opinions about bananas.
Building a GUI with Tkinter widgets
Start a new file in your editor called banana_survey.py
, and begin by importing tkinter
like so:
# banana_survey.py
"""A banana preferences survey written in Python with Tkinter"""
import tkinter as tk
As with hello_tkinter.py
, we need to create a root
window before we can create any widgets or other Tkinter objects:
root = tk.Tk()
Once again, we've called this object root
. The root
window can be configured in various ways; for example,...