mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #21402: tkinter.ttk now works when default root window is not set.
This commit is contained in:
parent
ffc1e6d42b
commit
b49eff25b7
3 changed files with 57 additions and 36 deletions
|
@ -272,7 +272,7 @@ def _list_from_statespec(stuple):
|
|||
it = iter(nval)
|
||||
return [_flatten(spec) for spec in zip(it, it)]
|
||||
|
||||
def _list_from_layouttuple(ltuple):
|
||||
def _list_from_layouttuple(tk, ltuple):
|
||||
"""Construct a list from the tuple returned by ttk::layout, this is
|
||||
somewhat the reverse of _format_layoutlist."""
|
||||
res = []
|
||||
|
@ -293,17 +293,16 @@ def _list_from_layouttuple(ltuple):
|
|||
indx += 2
|
||||
|
||||
if opt == 'children':
|
||||
if (tkinter._default_root and
|
||||
not tkinter._default_root.wantobjects()):
|
||||
val = tkinter._default_root.splitlist(val)
|
||||
val = _list_from_layouttuple(val)
|
||||
if not tk.wantobjects():
|
||||
val = tk.splitlist(val)
|
||||
val = _list_from_layouttuple(tk, val)
|
||||
|
||||
opts[opt] = val
|
||||
|
||||
return res
|
||||
|
||||
def _val_or_dict(options, func, *args):
|
||||
"""Format options then call func with args and options and return
|
||||
def _val_or_dict(tk, options, *args):
|
||||
"""Format options then call Tk command with args and options and return
|
||||
the appropriate result.
|
||||
|
||||
If no option is specified, a dict is returned. If a option is
|
||||
|
@ -311,14 +310,12 @@ def _val_or_dict(options, func, *args):
|
|||
Otherwise, the function just sets the passed options and the caller
|
||||
shouldn't be expecting a return value anyway."""
|
||||
options = _format_optdict(options)
|
||||
res = func(*(args + options))
|
||||
res = tk.call(*(args + options))
|
||||
|
||||
if len(options) % 2: # option specified without a value, return its value
|
||||
return res
|
||||
|
||||
if tkinter._default_root:
|
||||
res = tkinter._default_root.splitlist(res)
|
||||
return _dict_from_tcltuple(res)
|
||||
return _dict_from_tcltuple(tk.splitlist(res))
|
||||
|
||||
def _convert_stringval(value):
|
||||
"""Converts a value to, hopefully, a more appropriate Python object."""
|
||||
|
@ -396,7 +393,7 @@ class Style(object):
|
|||
a sequence identifying the value for that option."""
|
||||
if query_opt is not None:
|
||||
kw[query_opt] = None
|
||||
return _val_or_dict(kw, self.tk.call, self._name, "configure", style)
|
||||
return _val_or_dict(self.tk, kw, self._name, "configure", style)
|
||||
|
||||
|
||||
def map(self, style, query_opt=None, **kw):
|
||||
|
@ -466,7 +463,7 @@ class Style(object):
|
|||
lspec = "null" # could be any other word, but this may make sense
|
||||
# when calling layout(style) later
|
||||
|
||||
return _list_from_layouttuple(self.tk.splitlist(
|
||||
return _list_from_layouttuple(self.tk, self.tk.splitlist(
|
||||
self.tk.call(self._name, "layout", style, lspec)))
|
||||
|
||||
|
||||
|
@ -907,7 +904,7 @@ class Notebook(Widget):
|
|||
options to the corresponding values."""
|
||||
if option is not None:
|
||||
kw[option] = None
|
||||
return _val_or_dict(kw, self.tk.call, self._w, "tab", tab_id)
|
||||
return _val_or_dict(self.tk, kw, self._w, "tab", tab_id)
|
||||
|
||||
|
||||
def tabs(self):
|
||||
|
@ -984,7 +981,7 @@ class Panedwindow(Widget, tkinter.PanedWindow):
|
|||
Otherwise, sets the options to the corresponding values."""
|
||||
if option is not None:
|
||||
kw[option] = None
|
||||
return _val_or_dict(kw, self.tk.call, self._w, "pane", pane)
|
||||
return _val_or_dict(self.tk, kw, self._w, "pane", pane)
|
||||
|
||||
|
||||
def sashpos(self, index, newpos=None):
|
||||
|
@ -1223,7 +1220,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
|
|||
Otherwise, sets the options to the corresponding values."""
|
||||
if option is not None:
|
||||
kw[option] = None
|
||||
return _val_or_dict(kw, self.tk.call, self._w, "column", column)
|
||||
return _val_or_dict(self.tk, kw, self._w, "column", column)
|
||||
|
||||
|
||||
def delete(self, *items):
|
||||
|
@ -1282,7 +1279,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
|
|||
if option is not None:
|
||||
kw[option] = None
|
||||
|
||||
return _val_or_dict(kw, self.tk.call, self._w, 'heading', column)
|
||||
return _val_or_dict(self.tk, kw, self._w, 'heading', column)
|
||||
|
||||
|
||||
def identify(self, component, x, y):
|
||||
|
@ -1361,7 +1358,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
|
|||
values as given by kw."""
|
||||
if option is not None:
|
||||
kw[option] = None
|
||||
return _val_or_dict(kw, self.tk.call, self._w, "item", item)
|
||||
return _val_or_dict(self.tk, kw, self._w, "item", item)
|
||||
|
||||
|
||||
def move(self, item, parent, index):
|
||||
|
@ -1456,7 +1453,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
|
|||
values for the given tagname."""
|
||||
if option is not None:
|
||||
kw[option] = None
|
||||
return _val_or_dict(kw, self.tk.call, self._w, "tag", "configure",
|
||||
return _val_or_dict(self.tk, kw, self._w, "tag", "configure",
|
||||
tagname)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue