Next / Previous / Contents / TCC Help System / NM Tech homepage

20. class Swatch: Font and color samples

This class is a compound widget containing only two internal widgets.

Here is the class interface.

huey
# - - - - -   c l a s s   S w a t c h

class Swatch(Frame):
    """Compound widget for text/background display and font selection.

      Exports:
        Swatch ( parent, bg, fg ):
          [ (parent is a Frame) and
            (bg is the initial background color as a Color instance) and
            (fg is the initial foreground color as a Color instance) ->
              parent  :=  parent with a new Swatch widget added but not
                          gridded
              return that new Swatch widget ]

These methods set either the foreground or background color; see Section 20.2, “Swatch.setTextColor() and Section 20.3, “Swatch.setBgColor().

huey
        .setTextColor ( color ):
          [ color is a color as a Color instance ->
              self  :=  self with the text displayed in that color ]
        .setBgColor ( color ):
          [ color is a color as a Color instance ->
              self  :=  self with the background set to color ]

      Internal widgets:
        .__text:          [ a Text widget ]
        .__fontSelect:    [ a FontSelect widget ]

      Grid plan:  One vertical column.

The internal state includes the current foreground and background colors, and also the current font.

huey
      State/Invariants:
        .__textColor:   [ current text color as a Color ]
        .__bgColor:     [ current background color as a Color ]
        .__font:        [ current font as a tkFont.Font ]
    """