Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
FIGURE 18.4 The Bowling Average Calculator program.
You should recognize all the widgets used in the script1809.py program. This
program uses four Entry widgets—three to enter the bowling scores, and one to
display the resulting average. One important feature to notice is that the values
retrieved from the Entry widgets are strings, so you have to convert the values into
numeric values for the calculations.

Now you have all the skills you need to start creating fancy GUI programs in your Python scripts.


Summary


In this hour, you dove into the world of programming GUI programs. There are several different
libraries you can use for creating GUI programs, and in this hour, you used the tkinter library,
which comes installed in the standard Python libraries.


The tkinter library allows you to create windows with all the standard features that you’re used
to seeing in commercial GUI programs—text entry forms, selection boxes, buttons, and menu bars.
You just write the Python code to create the window, add the widgets you want to the window, and
then link methods to the events generated by the widgets.


In the next hour, we’ll take a look at how to create games using Python programming. There’s a great
tool available to help make creating games a breeze, and we’ll walk through just how to use that.


Q&A


Q. Can you link more than one widget to the same method?
A. Yes, you can use the same method for multiple events. For example, you can link a Button
widget to the same method that you link to from a Menu item.
Q. Can you link more than one method to a single widget?
Free download pdf