MCS 260 Fall 2021
Today we'll talk about making programs with graphical user interfaces (GUIs). How to do this?
Increasingly popular: Write a program accessed through a browser. HTML allows buttons, text entry boxes, drawing, etc..
Today: We'll build a GUI without a browser, using a toolkit, a library of functions for creating GUIs.
Tk is a cross-platform GUI toolkit originally created for the TCL programming language.
tkinter is the Python module providing an interface to Tk. It is the only GUI toolkit in the standard library.
tkinter dates from the mid-1990s and shows it age in some ways.
There are many GUI toolkits, but many are:
tkinter is not common for new projects, it is similar enough to other toolkits to make it useful to learn.
Widgets are standardized components of a GUI.
Create a window and hierarchy of widgets (buttons, sliders, etc.).
Specify functions to be called when user interacts with widgets, or in response to other events.
Start the GUI main loop, which never returns.
Key point: You lose control of what happens next. The program can only respond to things that happen in the GUI.
tkinter contains window setup functions, lots of constants, and misc. other stuff.
tkinter.ttk contains widgets for button, checkbox, text entry box, text label, drop-down menu, scrollbar, radio button (mutually exclusive choice), slider, etc.
Let's build a simple GUI application that shows a text label and buttons to:
tkinter.Tkor other widget)
Widgets used today
tkinter.ttk.Button— activate to perform an action
tkinter.ttk.Label— displays text, not directly editable