Figure 8-15. demoDlg color, askcolor dialog
If you press its OK button, it returns a data structure that identifies the selected color,
which can be used in all color contexts in tkinter. It includes RGB values and a hexa-
decimal color string (e.g., ((160, 160, 160), '#a0a0a0')). More on how this tuple can
be useful in a moment. If you press Cancel, the script gets back a tuple containing two
nones (Nones of the Python variety, that is).
Printing dialog results and passing callback data with lambdas
The dialog demo launcher bar displays standard dialogs and can be made to display
others by simply changing the dialogTable module it imports. As coded, though, it
really shows only dialogs; it would also be nice to see their return values so that we
know how to use them in scripts. Example 8-10 adds printing of standard dialog results
to the stdout standard output stream.
Example 8-10. PP4E\Gui\Tour\demoDlg-print.py
"""
similar, but show return values of dialog calls; the lambda saves data from
the local scope to be passed to the handler (button press handlers normally
get no arguments, and enclosing scope references don't work for loop variables)
and works just like a nested def statement: def func(key=key): self.printit(key)
"""
434 | Chapter 8: A tkinter Tour, Part 1