This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: ttk.Style.element_create using incorrect syntax
Type: behavior Stage: needs patch
Components: Tkinter Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: jmorgensen, markroseman, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2015-04-16 22:49 by jmorgensen, last changed 2022-04-11 14:58 by admin.

Messages (3)
msg241286 - (view) Author: (jmorgensen) Date: 2015-04-16 22:49
Style.element_create passes all spec elements as a single string into 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.

> def element_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)
>, "element", "create", elementname, etype,
>         spec, *opts)

And in _format_elemcreate:
>     spec = "%s %s" % (iname, imagespec)
>     ...
>     spec = "%s %s %s" % (class_name, part_id, statemap)

Reproduction (on win):

> >>> import ttk
> >>> Style().element_create('custom.test', 'vsapi', 'SPIN', 2)
>   File "<stdin>", line 1, in <module>
>   File "C:\Miniconda\lib\lib-tk\", line 466, in element_create
>     spec, *opts)
> _tkinter.TclError: missing required arguments 'class' and/or 'partId'

and, similarly:
> >>> import ttk
> >>> ttk.Style().element_create('custom.test', 'vsapi', 'SPIN', 2, width=5)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "C:\Miniconda\lib\lib-tk\", line 466, in element_create
>     spec, *opts)
> _tkinter.TclError: expected integer but got "-width"
msg241370 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-04-17 21:57
Reproduced on Win7, 3.4.3, with updated import: "from tkinter import ttk".  The example should serve as a test.
msg248149 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-06 21:25
This looks like it should be an easy for for someone who understands 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.
Date User Action Args
2022-04-11 14:58:15adminsetgithub: 68166
2015-08-06 21:25:09terry.reedysetnosy: + markroseman, - gpolo
messages: + msg248149
versions: + Python 3.6
2015-04-17 22:48:20serhiy.storchakasetassignee: serhiy.storchaka
2015-04-17 21:57:39terry.reedysetversions: + Python 3.4, Python 3.5
nosy: + terry.reedy

messages: + msg241370

type: behavior
stage: needs patch
2015-04-16 22:56:43ned.deilysetnosy: + gpolo, serhiy.storchaka
type: crash -> (no value)
2015-04-16 22:49:38jmorgensencreate