[3.12] gh-120211: Fix tkinter.ttk with Tcl/Tk 9.0 (GH-120213) (GH-120216)

* Use new methods for tracing Tcl variable.
* Fix Combobox.current() for empty combobox.
(cherry picked from commit d68a22e7a6)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-06-07 13:30:50 +02:00 committed by GitHub
parent ec139c8fae
commit ac68d83fec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -683,7 +683,10 @@ def current(self, newindex=None):
returns the index of the current value in the list of values
or -1 if the current value does not appear in the list."""
if newindex is None:
return self.tk.getint(self.tk.call(self._w, "current"))
res = self.tk.call(self._w, "current")
if res == '':
return -1
return self.tk.getint(res)
return self.tk.call(self._w, "current", newindex)
@ -1515,7 +1518,7 @@ def __init__(self, master=None, variable=None, from_=0, to=10, **kw):
self.label.place(anchor='n' if label_side == 'top' else 's')
# update the label as scale or variable changes
self.__tracecb = self._variable.trace_variable('w', self._adjust)
self.__tracecb = self._variable.trace_add('write', self._adjust)
self.bind('<Configure>', self._adjust)
self.bind('<Map>', self._adjust)
@ -1523,7 +1526,7 @@ def __init__(self, master=None, variable=None, from_=0, to=10, **kw):
def destroy(self):
"""Destroy this widget and possibly its associated variable."""
try:
self._variable.trace_vdelete('w', self.__tracecb)
self._variable.trace_remove('write', self.__tracecb)
except AttributeError:
pass
else:

View file

@ -0,0 +1 @@
Fix :mod:`tkinter.ttk` with Tcl/Tk 9.0.