-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorchooser.py
More file actions
40 lines (22 loc) · 814 Bytes
/
colorchooser.py
File metadata and controls
40 lines (22 loc) · 814 Bytes
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
from tkinter.commondialog import Dialog
class Chooser(Dialog):
command = "tk_chooseColor"
def _fixoptions(self):
try:
color = self.options["initialcolor"]
if isinstance(color, tuple):
self.options["initialcolor"] = "#%02x%02x%02x" % color
except KeyError:
pass
def _fixresult(self, widget, result):
if not result or not str(result):
return None, None
r, g, b = widget.winfo_rgb(result)
return (r//256, g//256, b//256), str(result)
def askcolor(color=None, **options):
if color:
options = options.copy()
options["initialcolor"] = color
return Chooser(**options).show()
if __name__ == "__main__":
print("color", askcolor())