diff options
author | Barry Warsaw <barry@python.org> | 1998-01-30 21:11:52 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1998-01-30 21:11:52 (GMT) |
commit | b6db1b94c58db54090a64216afc3f68503abcab2 (patch) | |
tree | c3d88a10b1d3440c1c10415531cdafe2c0482c55 /Tools/pynche/ChipViewer.py | |
parent | 7080a7f69e52f54a1d0386bf05494e83eeace568 (diff) | |
download | cpython-b6db1b94c58db54090a64216afc3f68503abcab2.zip cpython-b6db1b94c58db54090a64216afc3f68503abcab2.tar.gz cpython-b6db1b94c58db54090a64216afc3f68503abcab2.tar.bz2 |
mered Greg's suggestions, added docstring
Diffstat (limited to 'Tools/pynche/ChipViewer.py')
-rw-r--r-- | Tools/pynche/ChipViewer.py | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/Tools/pynche/ChipViewer.py b/Tools/pynche/ChipViewer.py index e173a62..2686d6b 100644 --- a/Tools/pynche/ChipViewer.py +++ b/Tools/pynche/ChipViewer.py @@ -1,3 +1,19 @@ +"""Color chip megawidget. +This widget is used for displaying a color. It consists of three components: + + label -- a Tkinter.Label, this is the chip's label which is displayed + about the color chip + chip -- A Tkinter.Frame, the frame displaying the color + name -- a Tkinter.Label, the name of the color + +In addition, the megawidget understands the following options: + + color -- the color displayed in the chip and name widgets + +When run as a script, this program displays a sample chip. +""" + + from Tkinter import * import Pmw @@ -6,10 +22,11 @@ class ChipWidget(Pmw.MegaWidget): _HEIGHT = 100 def __init__(self, parent=None, **kw): - optionsdefs = (('chipcolor', 'blue', self.__set_color), - ('width', self._WIDTH, self.__set_dims), - ('height', self._HEIGHT, self.__set_dims), - ('text', 'Color', self.__set_label), + optionsdefs = (('chip_borderwidth', 2, None), + ('chip_width', self._WIDTH, None), + ('chip_height', self._HEIGHT, None), + ('label_text', 'Color', None), + ('color', 'blue', self.__set_color), ) self.defineoptions(kw, optionsdefs) @@ -41,22 +58,12 @@ class ChipWidget(Pmw.MegaWidget): # Check keywords and initialize options self.initialiseoptions(ChipWidget) - # called whenever `chipcolor' option is set + # called whenever `color' option is set def __set_color(self): - color = self['chipcolor'] + color = self['color'] self.__chip['background'] = color self.__name['text'] = color - def __set_dims(self): - width = self['width'] - height = self['height'] - self.__chip.configure(width=width, height=height) - - def __set_label(self): - self.__label['text'] = self['text'] - -Pmw.forwardmethods(ChipWidget, Frame, '__chip') - if __name__ == '__main__': @@ -65,7 +72,8 @@ if __name__ == '__main__': exitbtn = Button(root, text='Exit', command=root.destroy) exitbtn.pack(side=BOTTOM) - widget = ChipWidget(root, chipcolor='red', width=200, - text='Selected Color') + widget = ChipWidget(root, color='red', + chip_width=200, + label_text='Selected Color') widget.pack() root.mainloop() |