The Tk wm attributes command takes option arguments
(from the Tk wm manual page):
wmattributeswindow ?optionvalueoptionvalue...?
And option arguments are normally given with keyword
arguments in Tkinter (most if not all widget creation
functions and widget commands). The attached patch
changes the wm_attributes method to take keyword
arguments, so top.wm_attributes(alpha=.8) will work as
expected (on Windows XP and Mac OS X).
w.wm_attributes() without arguments returns a dict instead of a tuple or a str.
E.g. it returns {'alpha': 1.0, 'topmost': 0, 'zoomed': 0, 'fullscreen': 0, 'type': ''} instead of ('-alpha', 1.0, '-topmost', 0, '-zoomed', 0, '-fullscreen', 0, '-type', ''), and, when wantobjects is 0, it returns {'alpha': '1.0', 'topmost': '0', 'zoomed': '0', 'fullscreen': '0', 'type': ''} instead of '-alpha 1.0 -topmost 0 -zoomed 0 -fullscreen 0 -type {}'.
This is a breaking change!
You still can get the old result when pass None as argument: w.wm_attributes(None).
When called with a single argument to get a value, it allow to omit the minus prefix. E.g. w.wm_attributes('alpha'). w.wm_attributes('-alpha') also supported, but is now silently deprecated.
It can be called with keyword arguments to set attributes. E.g. w.wm_attributes(alpha=0.5). Old way w.wm_attributes('-alpha', 0.5) also works, but it is now silently deprecated.
My request for unconditional changing the returned value was rejected: python/steering-council#211. Instead it was proposed to add an optional argument return_python_dict=False.
Activity
gregcouch commented on Jun 5, 2006
The Tk wm attributes command takes option arguments
(from the Tk wm manual page):
And option arguments are normally given with keyword
arguments in Tkinter (most if not all widget creation
functions and widget commands). The attached patch
changes the wm_attributes method to take keyword
arguments, so top.wm_attributes(alpha=.8) will work as
expected (on Windows XP and Mac OS X).
loewis commented on Jun 17, 2006
Logged In: YES
user_id=21627
This is an incompatible change. I also don't see the point;
should work just fine, no?
klappnase commented on Jul 20, 2006
Logged In: YES
user_id=797929
I do not have winXP or OSX available to actually test it,
but I doubt that
will work; from Tk documentation it looks like you will have
to write
which is in fact not what one would expect.
Maybe a better solution than Greg's patch was to change
wm_attributes() to accept both ways, like:
so that old code will not break and the more intuitive
version that Greg suggested is also legal.
gpolo commented on Jun 3, 2008
I'm adding my own version, this was done against python-trunk
pythongh-43457: Tkinter: fix design flaws in wm_attributes()
serhiy-storchaka commented on Oct 27, 2023
The proposed PR contains the following changes:
E.g. it returns {'alpha': 1.0, 'topmost': 0, 'zoomed': 0, 'fullscreen': 0, 'type': ''} instead of ('-alpha', 1.0, '-topmost', 0, '-zoomed', 0, '-fullscreen', 0, '-type', ''), and, when wantobjects is 0, it returns {'alpha': '1.0', 'topmost': '0', 'zoomed': '0', 'fullscreen': '0', 'type': ''} instead of '-alpha 1.0 -topmost 0 -zoomed 0 -fullscreen 0 -type {}'.
This is a breaking change!
You still can get the old result when pass None as argument: w.wm_attributes(None).
serhiy-storchaka commented on Oct 28, 2023
Opened a discussion https://discuss.python.org/t/tkinter-wm-attributes-needs-breaking-changes/37360.
serhiy-storchaka commented on Nov 14, 2023
My request for unconditional changing the returned value was rejected: python/steering-council#211. Instead it was proposed to add an optional argument return_python_dict=False.
gh-43457: Tkinter: fix design flaws in wm_attributes() (GH-111404)
pythongh-43457: Tkinter: fix design flaws in wm_attributes() (pythonG…