class ThresholdScale(Pmw
.MegaWidget
):
""" Megawidget containing a scale and an indicator.
def __init__(self
, parent
= None, **kw
):
# Define the megawidget options.
('colors', ('green', 'red'), None),
('value', None, Pmw
.INITOPT
),
self
.defineoptions(kw
, optiondefs
)
# Initialise base class (after defining options).
Pmw
.MegaWidget
.__init
__(self
, parent
)
interior
= self
.interior()
# Create the indicator component.
self
.indicator
= self
.createcomponent('indicator',
# Create the scale component.
self
.scale
= self
.createcomponent('scale',
command
= self
._doCommand
,
# Check keywords and initialise options.
def _doCommand(self
, valueStr
):
if self
.scale
.get() > self
['threshold']:
color
= self
['colors'][1]
color
= self
['colors'][0]
self
.indicator
.configure(background
= color
)
Pmw
.forwardmethods(ThresholdScale
, Tkinter
.Scale
, 'scale')
# Initialise Tkinter and Pmw.
root
.title('Pmw ThresholdScale demonstration')
# Create and pack two ThresholdScale megawidgets.
mega1
.pack(side
= 'left', padx
= 10, pady
= 10)
colors
= ('green', 'yellow'),
mega2
.pack(side
= 'left', padx
= 10, pady
= 10)