mirror of
https://github.com/python/cpython.git
synced 2025-07-31 07:04:42 +00:00
Issue #3767: Convert Tk object to string in tkColorChooser.
This commit is contained in:
parent
e2eb2b4bc3
commit
732479f50b
2 changed files with 9 additions and 5 deletions
|
@ -34,19 +34,22 @@ class Chooser(Dialog):
|
||||||
try:
|
try:
|
||||||
# make sure initialcolor is a tk color string
|
# make sure initialcolor is a tk color string
|
||||||
color = self.options["initialcolor"]
|
color = self.options["initialcolor"]
|
||||||
if type(color) == type(()):
|
if isinstance(color, tuple):
|
||||||
# assume an RGB triplet
|
# assume an RGB triplet
|
||||||
self.options["initialcolor"] = "#%02x%02x%02x" % color
|
self.options["initialcolor"] = "#%02x%02x%02x" % color
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _fixresult(self, widget, result):
|
def _fixresult(self, widget, result):
|
||||||
|
# result can be somethings: an empty tuple, an empty string or
|
||||||
|
# a Tcl_Obj, so this somewhat weird check handles that
|
||||||
|
if not result or not str(result):
|
||||||
|
return None, None # canceled
|
||||||
|
|
||||||
# to simplify application code, the color chooser returns
|
# to simplify application code, the color chooser returns
|
||||||
# an RGB tuple together with the Tk color string
|
# an RGB tuple together with the Tk color string
|
||||||
if not result:
|
|
||||||
return None, None # canceled
|
|
||||||
r, g, b = widget.winfo_rgb(result)
|
r, g, b = widget.winfo_rgb(result)
|
||||||
return (r/256, g/256, b/256), result
|
return (r/256, g/256, b/256), str(result)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -66,5 +69,4 @@ def askcolor(color = None, **options):
|
||||||
# test stuff
|
# test stuff
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
print "color", askcolor()
|
print "color", askcolor()
|
||||||
|
|
|
@ -91,6 +91,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #3767: Convert Tk object to string in tkColorChooser.
|
||||||
|
|
||||||
- Issue #3248: Allow placing ScrolledText in a PanedWindow.
|
- Issue #3248: Allow placing ScrolledText in a PanedWindow.
|
||||||
|
|
||||||
- Issue #4444: Allow assertRaises() to be used as a context handler, so that
|
- Issue #4444: Allow assertRaises() to be used as a context handler, so that
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue