1
2 from Tkinter import *
3
4 COLORS = [
5 "AliceBlue", "AntiqueWhite", "AntiqueWhite1",
6 "AntiqueWhite2", "AntiqueWhite3", "AntiqueWhite4",
7 "aquamarine", "aquamarine1", "aquamarine2", "aquamarine3",
8 "aquamarine4", "azure", "azure1", "azure2", "azure3",
9 "azure4", "beige", "bisque", "bisque1", "bisque2",
10 "bisque3", "bisque4", "black", "BlanchedAlmond", "blue",
11 "blue1", "blue2", "blue3", "blue4", "BlueViolet", "brown",
12 "brown1", "brown2", "brown3", "brown4", "burlywood",
13 "burlywood1", "burlywood2", "burlywood3", "burlywood4",
14 "CadetBlue", "CadetBlue1", "CadetBlue2", "CadetBlue3",
15 "CadetBlue4", "chartreuse", "chartreuse1", "chartreuse2",
16 "chartreuse3", "chartreuse4", "chocolate", "chocolate1",
17 "chocolate2", "chocolate3", "chocolate4", "coral", "coral1",
18 "coral2", "coral3", "coral4", "CornflowerBlue", "cornsilk",
19 "cornsilk1", "cornsilk2", "cornsilk3", "cornsilk4", "cyan",
20 "cyan1", "cyan2", "cyan3", "cyan4", "DarkGoldenrod",
21 "DarkGoldenrod1", "DarkGoldenrod2", "DarkGoldenrod3",
22 "DarkGoldenrod4", "DarkGreen", "DarkKhaki", "DarkOliveGreen",
23 "DarkOliveGreen1", "DarkOliveGreen2", "DarkOliveGreen3",
24 "DarkOliveGreen4", "DarkOrange", "DarkOrange1", "DarkOrange2",
25 "DarkOrange3", "DarkOrange4", "DarkOrchid", "DarkOrchid1",
26 "DarkOrchid2", "DarkOrchid3", "DarkOrchid4", "DarkSalmon",
27 "DarkSeaGreen", "DarkSeaGreen1", "DarkSeaGreen2", "DarkSeaGreen3",
28 "DarkSeaGreen4", "DarkSlateBlue", "DarkSlateGray", "DarkSlateGray1",
29 "DarkSlateGray2", "DarkSlateGray3", "DarkSlateGray4", "DarkSlateGrey",
30 "DarkTurquoise", "DarkViolet", "DeepPink", "DeepPink1", "DeepPink2",
31 "DeepPink3", "DeepPink4", "DeepSkyBlue", "DeepSkyBlue1",
32 "DeepSkyBlue2", "DeepSkyBlue3", "DeepSkyBlue4", "DimGray", "DimGrey",
33 "DodgerBlue", "DodgerBlue1", "DodgerBlue2", "DodgerBlue3",
34 "DodgerBlue4", "firebrick", "firebrick1", "firebrick2", "firebrick3",
35 "firebrick4", "FloralWhite", "ForestGreen", "gainsboro", "GhostWhite",
36 "gold", "gold1", "gold2", "gold3", "gold4", "goldenrod", "goldenrod1",
37 "goldenrod2", "goldenrod3", "goldenrod4", "gray", "gray0", "gray1",
38 "gray2", "gray3", "gray4", "gray5", "gray6", "gray7", "gray8", "gray9",
39 "gray10", "gray11", "gray12", "gray13", "gray14",
40 "gray15", "gray16", "gray17", "gray18", "gray19",
41 "gray20", "gray21", "gray22", "gray23", "gray24", "gray25",
42 "gray26", "gray27", "gray28", "gray29", "gray30",
43 "gray31", "gray32", "gray33", "gray34", "gray35", "gray36",
44 "gray37", "gray38", "gray39", "gray40", "gray41",
45 "gray42", "gray43", "gray44", "gray45", "gray46", "gray47",
46 "gray48", "gray49", "gray50", "gray51", "gray52",
47 "gray53", "gray54", "gray55", "gray56", "gray57", "gray58",
48 "gray59", "gray60", "gray61", "gray62", "gray63",
49 "gray64", "gray65", "gray66", "gray67", "gray68", "gray69",
50 "gray70", "gray71", "gray72", "gray73", "gray74",
51 "gray75", "gray76", "gray77", "gray78", "gray79",
52 "gray80", "gray81", "gray82", "gray83", "gray84", "gray85",
53 "gray86", "gray87", "gray88", "gray89", "gray90",
54 "gray91", "gray92", "gray93", "gray94", "gray95", "gray96",
55 "gray97", "gray98", "gray99", "gray100", "green", "green1", "green2",
56 "green3", "green4", "GreenYellow", "grey", "grey0", "grey1",
57 "grey2", "grey3", "grey4", "grey5", "grey6", "grey7", "grey8", "grey9",
58 "grey10", "grey11", "grey12", "grey13", "grey14",
59 "grey15", "grey16", "grey17", "grey18", "grey19",
60 "grey20", "grey21", "grey22", "grey23", "grey24", "grey25",
61 "grey26", "grey27", "grey28", "grey29", "grey30",
62 "grey31", "grey32", "grey33", "grey34", "grey35", "grey36",
63 "grey37", "grey38", "grey39", "grey40", "grey41",
64 "grey42", "grey43", "grey44", "grey45", "grey46", "grey47",
65 "grey48", "grey49", "grey50", "grey51", "grey52",
66 "grey53", "grey54", "grey55", "grey56", "grey57", "grey58",
67 "grey59", "grey60", "grey61", "grey62", "grey63",
68 "grey64", "grey65", "grey66", "grey67", "grey68", "grey69",
69 "grey70", "grey71", "grey72", "grey73", "grey74",
70 "grey75", "grey76", "grey77", "grey78", "grey79",
71 "grey80", "grey81", "grey82", "grey83", "grey84", "grey85",
72 "grey86", "grey87", "grey88", "grey89", "grey90",
73 "grey91", "grey92", "grey93", "grey94", "grey95", "grey96",
74 "grey97", "grey98", "grey99", "grey100", "honeydew", "honeydew1", "honeydew2",
75 "honeydew3", "honeydew4", "HotPink", "HotPink1", "HotPink2",
76 "HotPink3", "HotPink4", "IndianRed", "IndianRed1", "IndianRed2",
77 "IndianRed3", "IndianRed4", "ivory", "ivory1", "ivory2", "ivory3",
78 "ivory4", "khaki", "khaki1", "khaki2", "khaki3", "khaki4",
79 "lavender", "LavenderBlush", "LavenderBlush1", "LavenderBlush2",
80 "LavenderBlush3", "LavenderBlush4", "LawnGreen", "LemonChiffon",
81 "LemonChiffon1", "LemonChiffon2", "LemonChiffon3", "LemonChiffon4",
82 "LightBlue1", "LightBlue2", "LightBlue3", "LightBlue4", "LightCoral",
83 "LightCyan", "LightCyan1", "LightCyan2", "LightCyan3", "LightCyan4",
84 "LightGoldenrod", "LightGoldenrod1", "LightGoldenrod2",
85 "LightGoldenrod3", "LightGoldenrod4", "LightGoldenrodYellow",
86 "LightGray", "LightGrey", "LightPink", "LightPink1", "LightPink2",
87 "LightPink3", "LightPink4", "LightSalmon", "LightSalmon1", "LightSalmon2",
88 "LightSalmon3", "LightSalmon4", "LightSeaGreen", "LightSkyBlue",
89 "LightSkyBlue1", "LightSkyBlue2", "LightSkyBlue3", "LightSkyBlue4",
90 "LightSlateBlue", "LightSlateGray", "LightSlateGrey", "LightSteelBlue",
91 "LightSteelBlue1", "LightSteelBlue2", "LightSteelBlue3", "LightSteelBlue4",
92 "LightYellow", "LightYellow1", "LightYellow2", "LightYellow3", "LightYellow4",
93 "LimeGreen", "linen", "magenta", "magenta1", "magenta2", "magenta3",
94 "magenta4", "maroon", "maroon1", "maroon2", "maroon3", "maroon4",
95 "MediumAquamarine", "MediumBlue", "MediumOrchid", "MediumOrchid1",
96 "MediumOrchid2", "MediumOrchid3", "MediumOrchid4", "MediumPurple",
97 "MediumPurple1", "MediumPurple2", "MediumPurple3", "MediumPurple4",
98 "MediumSeaGreen", "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise",
99 "MediumVioletRed", "MidnightBlue", "MintCream", "MistyRose",
100 "MistyRose1", "MistyRose2", "MistyRose3", "MistyRose4", "moccasin",
101 "NavajoWhite", "NavajoWhite1", "NavajoWhite2", "NavajoWhite3",
102 "NavajoWhite4", "navy", "NavyBlue", "OldLace", "OliveDrab",
103 "OliveDrab1", "OliveDrab2", "OliveDrab3", "OliveDrab4", "orange",
104 "orange1", "orange2", "orange3", "orange4", "OrangeRed", "OrangeRed1",
105 "OrangeRed2", "OrangeRed3", "OrangeRed4", "orchid", "orchid1",
106 "orchid2", "orchid3", "orchid4", "PaleGreen1", "PaleGreen2",
107 "PaleGreen3", "PaleGreen4", "PaleTurquoise", "PaleTurquoise1",
108 "PaleTurquoise2", "PaleTurquoise3", "PaleTurquoise4", "PaleVioletRed",
109 "PaleVioletRed1", "PaleVioletRed2", "PaleVioletRed3", "PaleVioletRed4",
110 "PapayaWhip", "PeachPuff", "PeachPuff1", "PeachPuff2", "PeachPuff3",
111 "PeachPuff4", "peru", "pink", "pink1", "pink2", "pink3", "pink4",
112 "plum", "plum1", "plum2", "plum3", "plum4", "PowderBlue", "purple",
113 "purple1", "purple2", "purple3", "purple4", "red", "red1", "red2",
114 "red3", "red4", "RosyBrown", "RosyBrown1", "RosyBrown2", "RosyBrown3",
115 "RosyBrown4", "RoyalBlue", "RoyalBlue1", "RoyalBlue2", "RoyalBlue3",
116 "RoyalBlue4", "SaddleBrown", "salmon", "salmon1", "salmon2",
117 "salmon3", "salmon4", "SandyBrown", "SeaGreen", "SeaGreen1",
118 "SeaGreen2", "SeaGreen3", "SeaGreen4", "seashell", "seashell1",
119 "seashell2", "seashell3", "seashell4", "sienna", "sienna1", "sienna2",
120 "sienna3", "sienna4", "SkyBlue", "SkyBlue1", "SkyBlue2", "SkyBlue3",
121 "SkyBlue4", "SlateBlue", "SlateBlue1", "SlateBlue2", "SlateBlue3",
122 "SlateBlue4", "SlateGray", "SlateGray1", "SlateGray2", "SlateGray3",
123 "SlateGray4", "SlateGrey", "snow", "snow1", "snow2", "snow3", "snow4",
124 "SpringGreen", "SpringGreen1", "SpringGreen2", "SpringGreen3",
125 "SpringGreen4", "SteelBlue", "SteelBlue1", "SteelBlue2", "SteelBlue3",
126 "SteelBlue4", "tan", "tan1", "tan2", "tan3", "tan4", "thistle",
127 "thistle1", "thistle2", "thistle3", "thistle4", "tomato", "tomato1",
128 "tomato2", "tomato3", "tomato4", "turquoise", "turquoise1", "turquoise2",
129 "turquoise3", "turquoise4", "violet", "VioletRed", "VioletRed1", "VioletRed2",
130 "VioletRed3", "VioletRed4", "wheat", "wheat1", "wheat2", "wheat3",
131 "wheat4", "white", "WhiteSmoke", "yellow", "yellow1", "yellow2", "yellow3",
132 "yellow4", "YellowGreen"]
133
134 class ColorPanel(Frame):
135
136 def createWidgets(self):
137 self.QUIT = Button(self, text='QUIT', foreground='red',
138 command=self.quit)
139 self.QUIT.pack(side=BOTTOM, fill=BOTH)
140 self.name=Entry(self, width=60, fg='black')
141 self.name.pack(side=BOTTOM, fill=BOTH)
142 self.namev=StringVar()
143 self.name['textvariable'] = self.namev
144
145 self.canvas = Canvas(self, width=900, height=600)
146 self.canvas.create_rectangle(150,560,300,590,
147 fill='white', outline='')
148 self.canvas.create_rectangle(300,560,450,590,
149 outline='black')
150 self.canvas.create_rectangle(450,560,600,590,
151 fill='black', outline='')
152 self.backg = self.canvas.create_rectangle(600,560,850,590,
153 fill='white', outline='black')
154
155 row = 0
156 column = 0
157 size = 25
158 rowm = int(900/size) - 2
159
160 for color in COLORS:
161 x1 = size + (size * column)
162 y1 = size + (size * row)
163 x2 = x1 + size
164 y2 = y1 + size
165 dot = self.canvas.create_rectangle(x1, y1, x2, y2, fill=color,
166 tags=color)
167 self.canvas.tag_bind(dot, "<Any-Enter>", self.mouseEnter)
168
169 column = column + 1
170 if column > rowm:
171 row = row + 1
172 column = 0
173
174 self.canvas.pack(side=LEFT)
175
176 def mouseEnter(self, event):
177
178
179 tags = self.canvas.gettags('current')
180 self.canvas.delete('linex')
181 filler = tags[0]
182
183 rgb = self.winfo_rgb(filler)
184 colors = "#%02x%02x%02x" % (rgb[0]/256, rgb[1]/256, rgb[2]/256)
185 self.namev.set('%s : "%s"' % (filler, colors))
186
187 for x in [160, 310, 460]:
188 self.canvas.create_line(x,563,x+50,563,x+50,587,x+140,587, width=2, fill=filler, tags='linex')
189 self.canvas.itemconfig(self.backg, fill=filler)
190 for x, color in [(610,'white'), (630,'black'), (650,'red'), (670,'yellow'), (690,'blue'), (710,'green')]:
191 self.canvas.create_line(x,563,x+50,563,x+50,587,x+140,587, width=2, fill=color, tags='linex')
192 self.name.update_idletasks()
193
194 def __init__(self, master=None):
195 Frame.__init__(self, master)
196 Pack.config(self)
197 self.createWidgets()
198
199 cpanel = ColorPanel()
200
201 cpanel.mainloop()
202