summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tkinter/test_misc.py
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/test/test_tkinter/test_misc.py
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/test/test_tkinter/test_misc.py')
-rw-r--r--Lib/test/test_tkinter/test_misc.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/Lib/test/test_tkinter/test_misc.py b/Lib/test/test_tkinter/test_misc.py
index 7155350..81a20b6 100644
--- a/Lib/test/test_tkinter/test_misc.py
+++ b/Lib/test/test_tkinter/test_misc.py
@@ -437,6 +437,61 @@ class MiscTest(AbstractTkTest, unittest.TestCase):
self.assertTrue(str(vi).startswith(f'{vi.major}.{vi.minor}'))
+class WmTest(AbstractTkTest, unittest.TestCase):
+
+ def test_wm_attribute(self):
+ w = self.root
+ attributes = w.wm_attributes(return_python_dict=True)
+ self.assertIsInstance(attributes, dict)
+ attributes2 = w.wm_attributes()
+ self.assertIsInstance(attributes2, tuple)
+ self.assertEqual(attributes2[::2],
+ tuple('-' + k for k in attributes))
+ self.assertEqual(attributes2[1::2], tuple(attributes.values()))
+ # silently deprecated
+ attributes3 = w.wm_attributes(None)
+ if self.wantobjects:
+ self.assertEqual(attributes3, attributes2)
+ else:
+ self.assertIsInstance(attributes3, str)
+
+ for name in attributes:
+ self.assertEqual(w.wm_attributes(name), attributes[name])
+ # silently deprecated
+ for name in attributes:
+ self.assertEqual(w.wm_attributes('-' + name), attributes[name])
+
+ self.assertIn('alpha', attributes)
+ self.assertIn('fullscreen', attributes)
+ self.assertIn('topmost', attributes)
+ if w._windowingsystem == "win32":
+ self.assertIn('disabled', attributes)
+ self.assertIn('toolwindow', attributes)
+ self.assertIn('transparentcolor', attributes)
+ if w._windowingsystem == "aqua":
+ self.assertIn('modified', attributes)
+ self.assertIn('notify', attributes)
+ self.assertIn('titlepath', attributes)
+ self.assertIn('transparent', attributes)
+ if w._windowingsystem == "x11":
+ self.assertIn('type', attributes)
+ self.assertIn('zoomed', attributes)
+
+ w.wm_attributes(alpha=0.5)
+ self.assertEqual(w.wm_attributes('alpha'),
+ 0.5 if self.wantobjects else '0.5')
+ w.wm_attributes(alpha=1.0)
+ self.assertEqual(w.wm_attributes('alpha'),
+ 1.0 if self.wantobjects else '1.0')
+ # silently deprecated
+ w.wm_attributes('-alpha', 0.5)
+ self.assertEqual(w.wm_attributes('alpha'),
+ 0.5 if self.wantobjects else '0.5')
+ w.wm_attributes(alpha=1.0)
+ self.assertEqual(w.wm_attributes('alpha'),
+ 1.0 if self.wantobjects else '1.0')
+
+
class BindTest(AbstractTkTest, unittest.TestCase):
def setUp(self):