For gridding information, see Section 13, “class NamePicker: Select colors by name”.
# - - - N a m e P i c k e r . _ _ c r e a t e W i d g e t s
def __createWidgets ( self ):
"""Create all widgets."""
#-- 1 --
# [ self := self with a new Label to label the color
# name entry field
# self.__entryLabel := that Label ]
self.__entryLabel = Label ( self,
font=BUTTON_FONT, text="Type a color name:" )
rowx = 0
self.__entryLabel.grid ( row=rowx, column=0, sticky=W )
The Entry field has an important event
binding: if the user presses the Enter
key (which is called Return in Tkinter),
that means they have selected a color, so the callback
must be called. The binding uses the handler method
Section 13.3, “NamePicker.__entryHandler(): Handler
for the Enter key”.
#-- 2 --
# [ self := self with a new Entry whose control variable
# is self.__entryVar, and which calls self.__callback
# when the user presses the Enter key ]
self.__entryVar = StringVar()
self.__entry = Entry ( self, relief=SUNKEN,
font=BUTTON_FONT,
width=self.NAME_WIDTH,
textvariable=self.__entryVar )
rowx += 1
self.__entry.grid ( row=rowx, column=0, sticky=W )
self.__entry.bind ( "<Key-Return>", self.__entryHandler )
Placing the label for the color pick list is
straightforward. However, creating the color pick list
is pretty involved, so that logic is located in Section 14, “class PickList: The color names pick
list”.
#-- 3 --
# [ self := self with a Label added for the color pick list
# self.__pickLabel := that Label ]
self.__pickLabel = Label ( self,
font=BUTTON_FONT,
text="Or click on a name:" )
rowx += 1
self.__pickLabel.grid ( row=rowx, column=0, sticky=W )
#-- 4 --
# [ self := self with a PickList added containing
# the color pick list, with bindings that will call
# self.__callback when a color is clicked
# self.__pickList := that ScrolledList ]
self.__pickList = PickList ( self, self.__pickListHandler )
rowx += 1
self.__pickList.grid ( row=rowx, column=0, sticky=W )