/usr/share/doc/python-pmw-doc/html/example.py is in python-pmw-doc 1.3.2-6build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | import Tkinter
import Pmw
class ThresholdScale(Pmw.MegaWidget):
""" Megawidget containing a scale and an indicator.
"""
def __init__(self, parent = None, **kw):
# Define the megawidget options.
optiondefs = (
('colors', ('green', 'red'), None),
('threshold', 50, None),
('value', None, Pmw.INITOPT),
)
self.defineoptions(kw, optiondefs)
# Initialise base class (after defining options).
Pmw.MegaWidget.__init__(self, parent)
# Create the components.
interior = self.interior()
# Create the indicator component.
self.indicator = self.createcomponent('indicator',
(), None,
Tkinter.Frame, interior,
width = 16,
height = 16,
borderwidth = 2,
relief = 'raised')
self.indicator.grid()
# Create the scale component.
self.scale = self.createcomponent('scale',
(), None,
Tkinter.Scale, interior,
command = self._doCommand,
tickinterval = 20,
length = 200,
from_ = 100,
to = 0,
showvalue = 0)
self.scale.grid()
value = self['value']
if value is not None:
self.scale.set(value)
# Check keywords and initialise options.
self.initialiseoptions()
def _doCommand(self, valueStr):
if self.scale.get() > self['threshold']:
color = self['colors'][1]
else:
color = self['colors'][0]
self.indicator.configure(background = color)
Pmw.forwardmethods(ThresholdScale, Tkinter.Scale, 'scale')
# Initialise Tkinter and Pmw.
root = Pmw.initialise()
root.title('Pmw ThresholdScale demonstration')
# Create and pack two ThresholdScale megawidgets.
mega1 = ThresholdScale()
mega1.pack(side = 'left', padx = 10, pady = 10)
mega2 = ThresholdScale(
colors = ('green', 'yellow'),
threshold = 75,
value = 80,
indicator_width = 32,
scale_width = 25)
mega2.pack(side = 'left', padx = 10, pady = 10)
# Let's go.
root.mainloop()
|