summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-02-05 16:24:54 (GMT)
committerGitHub <noreply@github.com>2024-02-05 16:24:54 (GMT)
commitb4ba0f73d6eef3da321bb96aafd09dfbc572e95d (patch)
treeb7e4d26504fe8fcb7dcddc469508eab22afda319 /Lib/tkinter
parent992446dd5bd3fff92ea0f8064fb19eebfe105cef (diff)
downloadcpython-b4ba0f73d6eef3da321bb96aafd09dfbc572e95d.zip
cpython-b4ba0f73d6eef3da321bb96aafd09dfbc572e95d.tar.gz
cpython-b4ba0f73d6eef3da321bb96aafd09dfbc572e95d.tar.bz2
gh-43457: Tkinter: fix design flaws in wm_attributes() (GH-111404)
* When called with a single argument to get a value, it allow to omit the minus prefix. * It can be called with keyword arguments to set attributes. * w.wm_attributes(return_python_dict=True) returns a dict instead of a tuple (it will be the default in future). * Setting wantobjects to 0 no longer affects the result.
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/__init__.py51
-rw-r--r--Lib/tkinter/simpledialog.py2
2 files changed, 33 insertions, 20 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index a1567d3..2be9da2 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -2108,26 +2108,39 @@ class Wm:
aspect = wm_aspect
- def wm_attributes(self, *args):
- """This subcommand returns or sets platform specific attributes
-
- The first form returns a list of the platform specific flags and
- their values. The second form returns the value for the specific
- option. The third form sets one or more of the values. The values
- are as follows:
-
- On Windows, -disabled gets or sets whether the window is in a
- disabled state. -toolwindow gets or sets the style of the window
- to toolwindow (as defined in the MSDN). -topmost gets or sets
- whether this is a topmost window (displays above all other
- windows).
-
- On Macintosh, XXXXX
-
- On Unix, there are currently no special attribute values.
+ def wm_attributes(self, *args, return_python_dict=False, **kwargs):
+ """Return or sets platform specific attributes.
+
+ When called with a single argument return_python_dict=True,
+ return a dict of the platform specific attributes and their values.
+ When called without arguments or with a single argument
+ return_python_dict=False, return a tuple containing intermixed
+ attribute names with the minus prefix and their values.
+
+ When called with a single string value, return the value for the
+ specific option. When called with keyword arguments, set the
+ corresponding attributes.
"""
- args = ('wm', 'attributes', self._w) + args
- return self.tk.call(args)
+ if not kwargs:
+ if not args:
+ res = self.tk.call('wm', 'attributes', self._w)
+ if return_python_dict:
+ return _splitdict(self.tk, res)
+ else:
+ return self.tk.splitlist(res)
+ if len(args) == 1 and args[0] is not None:
+ option = args[0]
+ if option[0] == '-':
+ # TODO: deprecate
+ option = option[1:]
+ return self.tk.call('wm', 'attributes', self._w, '-' + option)
+ # TODO: deprecate
+ return self.tk.call('wm', 'attributes', self._w, *args)
+ elif args:
+ raise TypeError('wm_attribute() options have been specified as '
+ 'positional and keyword arguments')
+ else:
+ self.tk.call('wm', 'attributes', self._w, *self._options(kwargs))
attributes = wm_attributes
diff --git a/Lib/tkinter/simpledialog.py b/Lib/tkinter/simpledialog.py
index 538bbfc..0f0dc66 100644
--- a/Lib/tkinter/simpledialog.py
+++ b/Lib/tkinter/simpledialog.py
@@ -262,7 +262,7 @@ def _setup_dialog(w):
w.tk.call("::tk::unsupported::MacWindowStyle", "style",
w, "moveableModal", "")
elif w._windowingsystem == "x11":
- w.wm_attributes("-type", "dialog")
+ w.wm_attributes(type="dialog")
# --------------------------------------------------------------------
# convenience dialogues