User manual

86
GPIO.output(LED[3-j], True); time.sleep(t)
GPIO.output(LED[3-j], False)
The third case is similar to the first, with the difference that the LEDs are counted down backwards and thus
reversing the direction of the chaser’s run.
When this function is defined, the elements of the graphical user interface are created.
Label(root,
text=”Please click a button to start the chaser
").pack()
The text in the dialog is again defined as Label object. New is the definition of the three radio buttons.
for txt, m in pattern:
Radiobutton(root, text = txt, variable = v, value = m).pack(anchor=W)
The radio buttons are defined using a special for loop form. Instead of the loop counter, two variables are
specified which are counted in parallel. The two counters run through the elements of the list
pattern one
by one. The first count variable
txt adopts the first value of the pair of values: text to be displayed next to
the radio button. The second count variable
m adopts the number from the second value of each pair of
values of a pattern.
The loop creates three radio buttons that way, that have as the first parameter always
root and the widget
where the radio buttons are located. Tarameter
text of a radio button shows the text that should be
displayed, which in this case is read from the variable
txt. The parameter variable specifies a previously
declared Tk variable into which the value of the selected radio button is entered after the user has made a
selection.
The parameter
value specifies for each radio button a numerical value, which in this case is read from the
variable
m. When a user clicks on this radio button, the value of the parameter value is written to the under
variable entered variable. Each of the three radio buttons will be built into the dialog box according to their
definition using the method
.pack(). he parameter anchor=W ensures that the radio buttons are left-aligned
below each other.
Button(root, text="Start", command=LedOn).pack(side=LEFT)
The button is as defined as in the previous example.
root.mainloop(); GPIO.cleanup()
The main loop and the end of the programme correspond to the last example.
Start the program and select a a flashing pattern using the radio button. Via the variable
v the first selection
is preselected. If you use radio buttons in a dialog box, always aim to set a reasonable initial selection so
that undefined result are avoided, if the user has not selected anything. A click on
Start
launches the selected
pattern which is run five times. Select a different pattern after that.