Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6db1b9

Browse files
committed
mered Greg's suggestions, added docstring
1 parent 7080a7f commit b6db1b9

1 file changed

Lines changed: 26 additions & 18 deletions

File tree

Tools/pynche/ChipViewer.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
"""Color chip megawidget.
2+
This widget is used for displaying a color. It consists of three components:
3+
4+
label -- a Tkinter.Label, this is the chip's label which is displayed
5+
about the color chip
6+
chip -- A Tkinter.Frame, the frame displaying the color
7+
name -- a Tkinter.Label, the name of the color
8+
9+
In addition, the megawidget understands the following options:
10+
11+
color -- the color displayed in the chip and name widgets
12+
13+
When run as a script, this program displays a sample chip.
14+
"""
15+
16+
117
from Tkinter import *
218
import Pmw
319

@@ -6,10 +22,11 @@ class ChipWidget(Pmw.MegaWidget):
622
_HEIGHT = 100
723

824
def __init__(self, parent=None, **kw):
9-
optionsdefs = (('chipcolor', 'blue', self.__set_color),
10-
('width', self._WIDTH, self.__set_dims),
11-
('height', self._HEIGHT, self.__set_dims),
12-
('text', 'Color', self.__set_label),
25+
optionsdefs = (('chip_borderwidth', 2, None),
26+
('chip_width', self._WIDTH, None),
27+
('chip_height', self._HEIGHT, None),
28+
('label_text', 'Color', None),
29+
('color', 'blue', self.__set_color),
1330
)
1431
self.defineoptions(kw, optionsdefs)
1532

@@ -41,22 +58,12 @@ def __init__(self, parent=None, **kw):
4158
# Check keywords and initialize options
4259
self.initialiseoptions(ChipWidget)
4360

44-
# called whenever `chipcolor' option is set
61+
# called whenever `color' option is set
4562
def __set_color(self):
46-
color = self['chipcolor']
63+
color = self['color']
4764
self.__chip['background'] = color
4865
self.__name['text'] = color
4966

50-
def __set_dims(self):
51-
width = self['width']
52-
height = self['height']
53-
self.__chip.configure(width=width, height=height)
54-
55-
def __set_label(self):
56-
self.__label['text'] = self['text']
57-
58-
Pmw.forwardmethods(ChipWidget, Frame, '__chip')
59-
6067

6168

6269
if __name__ == '__main__':
@@ -65,7 +72,8 @@ def __set_label(self):
6572

6673
exitbtn = Button(root, text='Exit', command=root.destroy)
6774
exitbtn.pack(side=BOTTOM)
68-
widget = ChipWidget(root, chipcolor='red', width=200,
69-
text='Selected Color')
75+
widget = ChipWidget(root, color='red',
76+
chip_width=200,
77+
label_text='Selected Color')
7078
widget.pack()
7179
root.mainloop()

0 commit comments

Comments
 (0)