4 class ThresholdScale(Pmw.MegaWidget):
5 """ Megawidget containing a scale and an indicator.
8 def __init__(self, parent = None, **kw):
10 # Define the megawidget options.
12 ('colors', ('green', 'red'), None),
13 ('threshold', 50, None),
14 ('value', None, Pmw.INITOPT),
16 self.defineoptions(kw, optiondefs)
18 # Initialise base class (after defining options).
19 Pmw.MegaWidget.__init__(self, parent)
21 # Create the components.
22 interior = self.interior()
24 # Create the indicator component.
25 self.indicator = self.createcomponent('indicator',
27 Tkinter.Frame, interior,
34 # Create the scale component.
35 self.scale = self.createcomponent('scale',
37 Tkinter.Scale, interior,
38 command = self._doCommand,
50 # Check keywords and initialise options.
51 self.initialiseoptions()
53 def _doCommand(self, valueStr):
54 if self.scale.get() > self['threshold']:
55 color = self['colors'][1]
57 color = self['colors'][0]
58 self.indicator.configure(background = color)
60 Pmw.forwardmethods(ThresholdScale, Tkinter.Scale, 'scale')
62 # Initialise Tkinter and Pmw.
63 root = Pmw.initialise()
64 root.title('Pmw ThresholdScale demonstration')
66 # Create and pack two ThresholdScale megawidgets.
67 mega1 = ThresholdScale()
68 mega1.pack(side = 'left', padx = 10, pady = 10)
70 mega2 = ThresholdScale(
71 colors = ('green', 'yellow'),
76 mega2.pack(side = 'left', padx = 10, pady = 10)