mirror of
https://github.com/python/cpython.git
synced 2025-09-10 18:58:35 +00:00
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.
This commit is contained in:
parent
992446dd5b
commit
b4ba0f73d6
6 changed files with 104 additions and 19 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue