summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-09-27 11:05:05 (GMT)
committerGitHub <noreply@github.com>2022-09-27 11:05:05 (GMT)
commitadbed2d542a815b8175db965742211856b19b52f (patch)
tree02836d64eb0d9bf35c5519a8a69f11fb0e408dbf /Lib/tkinter
parent68c46ae68b6e0c36a12e37285fff9ce0782ed01e (diff)
downloadcpython-adbed2d542a815b8175db965742211856b19b52f.zip
cpython-adbed2d542a815b8175db965742211856b19b52f.tar.gz
cpython-adbed2d542a815b8175db965742211856b19b52f.tar.bz2
gh-73588: Fix generation of the default name of tkinter.Checkbutton. (GH-97547)
Previously, checkbuttons in different parent widgets could have the same short name and share the same state if arguments "name" and "variable" are not specified. Now they are globally unique.
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/__init__.py12
-rw-r--r--Lib/tkinter/dialog.py2
-rw-r--r--Lib/tkinter/tix.py2
3 files changed, 13 insertions, 3 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index 2963202..3564469 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -2619,7 +2619,7 @@ class BaseWidget(Misc):
if kw:
cnf = _cnfmerge((cnf, kw))
self.widgetName = widgetName
- BaseWidget._setup(self, master, cnf)
+ self._setup(master, cnf)
if self._tclCommands is None:
self._tclCommands = []
classes = [(k, v) for k, v in cnf.items() if isinstance(k, type)]
@@ -3038,6 +3038,8 @@ class Canvas(Widget, XView, YView):
return self.tk.call(self._w, 'type', tagOrId) or None
+_checkbutton_count = 0
+
class Checkbutton(Widget):
"""Checkbutton widget which is either in on- or off-state."""
@@ -3053,6 +3055,14 @@ class Checkbutton(Widget):
underline, variable, width, wraplength."""
Widget.__init__(self, master, 'checkbutton', cnf, kw)
+ def _setup(self, master, cnf):
+ if not cnf.get('name'):
+ global _checkbutton_count
+ name = self.__class__.__name__.lower()
+ _checkbutton_count += 1
+ cnf['name'] = f'!{name}{_checkbutton_count}'
+ super()._setup(master, cnf)
+
def deselect(self):
"""Put the button in off-state."""
self.tk.call(self._w, 'deselect')
diff --git a/Lib/tkinter/dialog.py b/Lib/tkinter/dialog.py
index 8ae2140..36ae6c2 100644
--- a/Lib/tkinter/dialog.py
+++ b/Lib/tkinter/dialog.py
@@ -11,7 +11,7 @@ class Dialog(Widget):
def __init__(self, master=None, cnf={}, **kw):
cnf = _cnfmerge((cnf, kw))
self.widgetName = '__dialog__'
- Widget._setup(self, master, cnf)
+ self._setup(master, cnf)
self.num = self.tk.getint(
self.tk.call(
'tk_dialog', self._w,
diff --git a/Lib/tkinter/tix.py b/Lib/tkinter/tix.py
index 44ecae1..ce21826 100644
--- a/Lib/tkinter/tix.py
+++ b/Lib/tkinter/tix.py
@@ -310,7 +310,7 @@ class TixWidget(tkinter.Widget):
del cnf[k]
self.widgetName = widgetName
- Widget._setup(self, master, cnf)
+ self._setup(master, cnf)
# If widgetName is None, this is a dummy creation call where the
# corresponding Tk widget has already been created by Tix