You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ttk.Style.element_create using incorrect tk.call syntax #68166
Style.element_create passes all spec elements as a single string into tk.call rather than breaking up arguments into "words." However, it passes the options properly as a list.
This causes python to crash with a stacktrace like the one below.
defelement_create(self, elementname, etype, *args, **kw):
"""Create a new element in the current theme of given etype."""spec, opts=_format_elemcreate(etype, False, *args, **kw)
self.tk.call(self._name, "element", "create", elementname, etype,
spec, *opts)
This looks like it should be an easy for for someone who understands tcl.call syntax. When we add ttk to Idle, I do not expect to use element_create, but maybe someone will want to to create a custom theme.
There are two ways to create new elements in Tkinter. One is by calling the elemnt_create() methods, and the other one by calling the theme_create() or theme_settings() method and using the elemnt_create key in the settings dict. In the former case it calls the ttk:style element create command directly, in the latter case it formats a script containing the ttk:style element create command and passes it as argument to the ttk:style theme create or the ttk:style theme settings command. There are enough differences between these two paths, so I expected that at least the latter works correctly. But it turned out that both ways do not work and never worked since adding this code in the stdlib. So it makes sense to consider it as a new feature rather than a bugfix. It should be documented correspondingly, and older versions should be made to raise more explicit exception when try to use the "vsapi" factory.
It is also an opportunity to change the Python API (which never worked) to closer match the Tk API. I.e. instead of
Activity
jmorgensen commentedon Apr 16, 2015
Style.element_create passes all spec elements as a single string into tk.call rather than breaking up arguments into "words." However, it passes the options properly as a list.
This causes python to crash with a stacktrace like the one below.
And in _format_elemcreate:
Reproduction (on win):
and, similarly:
terryjreedy commentedon Apr 17, 2015
Reproduced on Win7, 3.4.3, with updated import: "from tkinter import ttk". The example should serve as a test.
terryjreedy commentedon Aug 6, 2015
This looks like it should be an easy for for someone who understands tcl.call syntax. When we add ttk to Idle, I do not expect to use element_create, but maybe someone will want to to create a custom theme.
pythongh-68166: Fix support of "vsapi" in ttk.Style.element_create()
serhiy-storchaka commentedon Oct 28, 2023
There are two ways to create new elements in Tkinter. One is by calling the
elemnt_create()methods, and the other one by calling thetheme_create()ortheme_settings()method and using theelemnt_createkey in the settings dict. In the former case it calls thettk:style element createcommand directly, in the latter case it formats a script containing thettk:style element createcommand and passes it as argument to thettk:style theme createor thettk:style theme settingscommand. There are enough differences between these two paths, so I expected that at least the latter works correctly. But it turned out that both ways do not work and never worked since adding this code in the stdlib. So it makes sense to consider it as a new feature rather than a bugfix. It should be documented correspondingly, and older versions should be made to raise more explicit exception when try to use the "vsapi" factory.It is also an opportunity to change the Python API (which never worked) to closer match the Tk API. I.e. instead of
it should be
or
or
pythongh-68166: Tkinter: Add tests and examples for element_create()
gh-68166: Tkinter: Add tests and examples for element_create() (GH-11…
pythongh-68166: Tkinter: Add tests and examples for element_create() (p…
pythongh-68166: Tkinter: Add tests and examples for element_create() (p…
gh-68166: Add support of "vsapi" in ttk.Style.element_create() (GH-11…
[3.11] gh-68166: Tkinter: Add tests and examples for element_create() (…
[3.12] gh-68166: Tkinter: Add tests and examples for element_create() (…
pythongh-68166: Tkinter: Add tests and examples for element_create() (p…
pythongh-68166: Add support of "vsapi" in ttk.Style.element_create() (p…
pythongh-68166: Tkinter: Add tests and examples for element_create() (p…
pythongh-68166: Add support of "vsapi" in ttk.Style.element_create() (p…