Next / Previous / Contents / Shipman's homepage

7.2. Controls._createWidgets()

For details of the layout and grid plans, see Section 7, “class Controls: Controls frame”.

fontselect.py
    def _createWidgets(self):
        """Widget layout.
        """

First we set up the three items gridded in self.

fontselect.py
        #-- 1 --
        # [ self  :=  self with a new Label added and gridded
        #             with a string control variable
        #   self.annunciator  :=  that Label
        #   self._fontName   :=  that control variable ]
        self._fontName = tk.StringVar()
        self.annunciator = tk.Label(self,
            font=self.fontSelect.regularFont, 
            textvariable=self._fontName,
            text="")
        rowx = 0
        self.annunciator.grid(row=rowx, sticky=tk.W)

The width and height options of the Text widget are in lines and characters, respectively. This gives a bit of room for the user to add or change text.

fontselect.py
        #-- 2 --
        # [ self  :=  self with a new Text widget added and gridded,
        #             displaying SAMPLE_TEXT
        #   self.sample  :=  that widget ]
        self.sample = tk.Text(self,
            width=20, height=2,
            font=self.fontSelect.regularFont)
        rowx  +=  1
        self.sample.grid(row=rowx, sticky=tk.W)
        self.sample.insert(tk.END, SAMPLE_TEXT)

The self.buttons frame is made to stick to the left (west) side of the containing column by using sticky=tk.W when it is gridded.

fontselect.py
        #-- 3 --
        # [ self  :=  self with a new Frame widget added and gridded
        #   self.buttons  :=  that widget ]
        self.buttons = tk.Frame(self)
        rowx  +=  1
        self.buttons.grid(row=rowx, sticky=tk.W)

The creation and gridding of the remaining controls is done in Section 7.3, “Controls._createButtons(): Lay out the small controls frame”.

fontselect.py
        #-- 4 --
        # [ self  :=  self with .sizeLabel, .sizeField, .sizeButton,
        #       .boldButton, and .italicButton added and gridded ]
        self._createButtons()