User manual
89
Converting integers to floating-point values
The result of a calculation is automatically saved as floating point number if at least one of the values in
the formula is a floating point number. If all values in the formula are integers (Integer), the result will
also be reduced to an integer.
The definition of the label and the radio buttons in the dialog box are taken from the previous example.
Label(root,
Label(root, text=”Speed").pack()
Another label is written in the dialog box for the slider declaration. Since this does not contain any
parameters in the
pack()method, it is centered horizontally below the radio buttons.
Scale(root, orient=HORIZONTAL, from_ = 1, to = 10, variable = g).pack()
The slider is an object of type Scale, which shall contain root as a first parameter like all objects in the
dialog box. The parameters
orient=HORIZONTAL indicates that the slider is horizontal. Without this
parameter, it would be in a vertical position. The parameters
from_ and to specify the slider’s start and end
values. Note the notation
from_ because from without underscore is a term reserved in Python to import
libraries. The parameter
variablespecifies a previously declared Tk variable, where the currently set value
of the slider is entered. The start value is taken from the value which was defined for the variable
declaration, which in this case is
5.
The slider is centered horizontally in the dialog box by means of the
pack() method.
The other program components - the
Start
button, the main loop and the end of the program - are taken from
the previous example without any alteration.
Start the program, select a flashing pattern and set the speed. Higher settings let the pattern blink faster.
When you click on the
Start
button function LedOn()reads the selected flashing pattern from the radio
buttons and also the speed from the position of the slider.
11 PiDance and LEDs
In the late 70’s, before any real computer games, there was an electronic game with four colored lamps,
which in 1979 was awarded in the very first selection list the Game of the Year. The game was known in
Germany under the name
Senso
. Atari released a replica under the name of
Touch Me
which had the size of
a pocket calculator. Another replica appeared as
Einstein,
and on the English speaking market Senso was
marketed as
Simon
.
Raspbian provides a graphical version of this game with the
Python Games
under the name
Simulate
.