demo objects was something more useful, like a text editor, calculator, or clock, you’ll
better appreciate the point of this example.
Besides demo object frames, this composite window also contains no fewer than five
instances of the Quitter button we wrote earlier (all of which verify the request and any
one of which can end the GUI) and a States button to dump the current values of all
the embedded demo objects at once (it calls each object’s report method, if it has one).
Here is a sample of the sort of output that shows up in the stdout stream after interacting
with widgets on this display; States output is in bold:
C:\...\PP4E\Gui\Tour> python demoAll_frm.py
in onMove 0
in onMove 0
demoDlg: none
demoCheck: 0 0 0 0 0
demoRadio: Error
demoScale: 0
you pressed Input
result: 1.234
in onMove 1
demoDlg: none
demoCheck: 1 0 1 1 0
demoRadio: Input
demoScale: 1
you pressed Query
result: yes
in onMove 2
You picked 2
None
in onMove 3
You picked 3
C:/Users/mark/Stuff/Books/4E/PP4E/dev/Examples/PP4E/Launcher.py
3
Query
1 1 1 1 0
demoDlg: none
demoCheck: 1 1 1 1 0
demoRadio: Query
demoScale: 3
Importing by name string
The only substantially tricky part of this script is its use of Python’s built-in
import function to import a module by a name string. Look at the following two
lines from the script’s addComponents function:
module = __import__(demo) # import module by name string
part = module.Demo(root) # attach an instance of its Demo
This is equivalent to saying something like this:
import 'demoDlg'
part = 'demoDlg'.Demo(root)
Running GUI Code Three Ways | 473