In this module we will be covering Graphical User Interface programming. We will look at the tkinter module, and look at how we use widgets in PYTHON. We will also examine how we use radio and check buttons for screen output.
Graphical User Interface
A graphical user interface allows the user to interact with the operating system and other programs using graphical elements such as icons, buttons, and dialog boxes.
A user interface is where the user interfaces with the computer program that is running. One interface consists of hardwre devices, and another is the way the operating system accepts commands from the user.
Early programming language could only communicate this way through the Command Line. A command line displays a prompt character(s) and the user types a command, which is then executed. In the 1980s GUIs came into use. This allows the user to interact with the operationg system and other programs through graphical elements on the screen.
Much of the interaction is done through "dialog boxes" which are small windows that display information and allow the user to perform actions. GUI programs are Event-driven. The user determines the order in which things happen.
The tkinter Module
The tkinter Module is used to create simple GUI programs. This uses the Tk interface - a GUI library called Tk that contains many functions to use. There are many other GUI libraries, but this one comes with the PYTHON programming language. The GUI program presents a window that shows various graphical "widgets" that the user can interact with or view. Some of these are:
Button a button that can cause an action to occur when it is clicked
Canvas a rectangular area that can be used to display graphics
Checkbutton a button that my be in either the "on" or "off" positon
Entry an area in which the user may type a single line of input from the keyboard
Frame a container that can hold other widgets
Label an area that displays one line of text or an image
Listbox a list from which the user may select an item
Menu a list of menu choices that are displayed when the user clicks a Menubutton widget
Menubutton a menu that is displayed on the screen and may be clicked by the user
Message displays multiple lines of text
Radiobutton a widget thata can be either selected or deselected. These are usually in groups where the user selects one
Scale a widget that allows the user to select a value by moving a slider along a track
Scrollbar can be used with some other types of widgets to provide scrolling ability
Text a widget that allows the user to enter multiple lines of text input
Toplevel a container, like a Frame, but displayed in its own window
Radio Buttons and Check Buttons
Radio buttons are useful when you want the user to select one choice from several possible options. tkinter module provides a class named "IntVar" that can be used along with Radiobutton widgets.
Check buttons appear as a small box with a label appearing next to it. Check buttons, like radiobuttons, can be selected or deselected. You may select any or all of the check buttons for a group. You use the tkinter module's Checkbutton class to create Checkbutton widgets.