User manual

81
root.mainloop() The main program has only this single line. It starts the main loop mainloop(), a method
of the
root widget. This programme loop waits for the user to activate a widget which will thus trigger an
action.
There is no need in Tkinter to specifically define the x-icon at the top right that closes the window. If the user
closes the main window
root, the main loop mainloop ()is terminated automatically.
GPIO.cleanup() The programme continues running until it comes to the last line and with it closes the
open GPIO ports.
After starting the programme a dialog box appears on-screen. Click on the button
On
to turn on the LED, then
on
Off
to turn it off.
10.2 Controlling chaser by a graphical user interface
The Python library Tkinter provides far more control elements than just these simple buttons. With radio
buttons you can build menus, where the user can select one of several options.
What are radio buttons?
The name "Radio Button" is actually derived from those old radios that featured radio station buttons for
pre-set radio stations. Whenever you hit one of those keys, the last one pressed automatically jumped out
using a refined mechanism. Radio buttons feature the same behaviour. If the user selects an option, the
others will automatically be turned off.
The next experiment shows different LED patterns similar to those of the experiment “Colorful LED patterns
and chaser lights”. However, unlike there, the user is not required to enter numbers into the screen of the
text input, instead chooses comfortably from a simple list of desired patterns.
Fig. 10.3: The dialog box offers three LED patterns to choose from.
The assembly of the circuit is the same as in the experiment “Colourful LED patterns and chaser lights".