This class is a compound widget that gives the user two
different ways to select a color by its name. They may
type the name directly into an Entry
widget. Most of the vertical space below this Entry contains a ScrolledList that
displays a prefabricated list of color names; the user may
instead click on any of these.
# - - - - - c l a s s N a m e P i c k e r
class NamePicker(Frame):
"""A compound widget for selecting a color by its name.
Exports:
NamePicker ( parent, callback=None ):
[ (parent is a Frame) and
(callback is a function or None) ->
parent := parent with a new NamePicker widget
added but not gridded, that calls callback
whenever a color is selected
return that NamePicker widget ]
Contained widgets:
.__entryLabel: [ a Label widget that labels self.__entry ]
.__entry: [ an Entry widget for entering a color name ]
.__pickLabel: [ a Label widget that labels self.__pickList ]
.__pickList: [ a ScrolledList widget with color names ]
Grid plan: Vertical stacking.
Private attributes include .__callback, the
callback function, and a StringVar control
variable linked to the .__entry widget.
State/Invariants:
.__parent: [ as passed to constructor ]
.__callback: [ as passed to constructor ]
.__entryVar:
[ a StringVar control variable for self.__entry ]
"""
The width of the Entry field, a manifest
constant, is a class variable.
NAME_WIDTH = 20