The constructor for a class that inherits from Frame is pretty stereotyped: call the parent
class's constructor, then create the widgets.
def __init__ ( self, master=None, font=None, listCount=None,
observer=None ):
"""Constructor for the FontSelect widget.
"""
#-- 1 --
# [ master := master with a new Frame widget added
# self := that Frame ]
Frame.__init__ ( self, master, relief=RIDGE,
borderwidth=4 )
We export the usual font for controls as the .regularFont attribute.
#-- 2 --
self.regularFont = tkFont.Font (
family="new century schoolbook", size="13" )
Next, we process the various constructor arguments.
If a font was passed in, we store it
in self.listFont; the default value is
the regular font.
#-- 3 --
# [ if font is None ->
# self.listFont := self.regularFont
# else ->
# self.listFont := font ]
self.listFont = font or self.regularFont
#-- 4 --
# [ if listCount is None ->
# self.__listCount := LISTBOX_HEIGHT
# else ->
# self.__listCount := listCount ]
self.__listCount = listCount or LISTBOX_HEIGHT
If an observer function was passed in, put it in self.__observerList.
#-- 5 --
# [ if observer is not None ->
# self.__observerList := [ observer ]
# else ->
# self.__observerList := an empty list ]
self.__observerList = []
if observer:
self.__observerList.append ( observer )
For widget creation, see Section 5.3, “FontSelect.__createWidgets(): Widget
placement”.
#-- 6 --
# [ self := self with all widgets and control linkages ]
self.__createWidgets()