Skip to content

ttk.Style.element_create using incorrect tk.call syntax #68166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jmorgensen mannequin opened this issue Apr 16, 2015 · 4 comments
Closed

ttk.Style.element_create using incorrect tk.call syntax #68166

jmorgensen mannequin opened this issue Apr 16, 2015 · 4 comments
Assignees
Labels
3.13 bugs and security fixes topic-tkinter type-bug An unexpected behavior, bug, or error type-feature A feature request or enhancement

Comments

@jmorgensen
Copy link
Mannequin

jmorgensen mannequin commented Apr 16, 2015

BPO 23978
Nosy @terryjreedy, @roseman, @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/serhiy-storchaka'
closed_at = None
created_at = <Date 2015-04-16.22:49:38.007>
labels = ['type-bug', 'expert-tkinter']
title = 'ttk.Style.element_create using incorrect tk.call syntax'
updated_at = <Date 2015-08-06.21:25:09.278>
user = 'https://bugs.python.org/jmorgensen'

bugs.python.org fields:

activity = <Date 2015-08-06.21:25:09.278>
actor = 'terry.reedy'
assignee = 'serhiy.storchaka'
closed = False
closed_date = None
closer = None
components = ['Tkinter']
creation = <Date 2015-04-16.22:49:38.007>
creator = 'jmorgensen'
dependencies = []
files = []
hgrepos = []
issue_num = 23978
keywords = []
message_count = 3.0
messages = ['241286', '241370', '248149']
nosy_count = 4.0
nosy_names = ['terry.reedy', 'markroseman', 'serhiy.storchaka', 'jmorgensen']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue23978'
versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

Linked PRs

@jmorgensen
Copy link
Mannequin Author

jmorgensen mannequin commented 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.

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)
    self.tk.call(self._name, "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\ttk.py", 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\ttk.py", line 466, in element_create
    spec, *opts)
_tkinter.TclError: expected integer but got "-width"

@jmorgensen jmorgensen mannequin added type-crash A hard crash of the interpreter, possibly with a core dump topic-tkinter labels Apr 16, 2015
@ned-deily ned-deily removed the type-crash A hard crash of the interpreter, possibly with a core dump label Apr 16, 2015
@terryjreedy
Copy link
Member

Reproduced on Win7, 3.4.3, with updated import: "from tkinter import ttk". The example should serve as a test.

@terryjreedy terryjreedy added the type-bug An unexpected behavior, bug, or error label Apr 17, 2015
@serhiy-storchaka serhiy-storchaka self-assigned this Apr 17, 2015
@terryjreedy
Copy link
Member

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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Oct 27, 2023
* Fix and document support of "vsapi" element type in
  tkinter.ttk.Style.element_create().
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.
@serhiy-storchaka
Copy link
Member

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

        style.element_create('pin', 'vsapi', 'EXPLORERBAR', 3,
                             ('pressed', '!selected', 3),
                             ('active', '!selected', 2),
                             ('pressed', 'selected', 6),
                             ('active', 'selected', 5),
                             ('selected', 4),
                             ('', 1))

it should be

        style.element_create('pin', 'vsapi', 'EXPLORERBAR', 3, [
                             ('pressed', '!selected', 3),
                             ('active', '!selected', 2),
                             ('pressed', 'selected', 6),
                             ('active', 'selected', 5),
                             ('selected', 4),
                             ('', 1)])

or

        style.element_create('pin', 'vsapi', 'EXPLORERBAR', 3, [
                             (('pressed', '!selected'), 3),
                             (('active', '!selected'), 2),
                             (('pressed', 'selected'), 6),
                             (('active', 'selected'), 5),
                             (('selected',), 4),
                             ((), 1)])

or

        style.element_create('pin', 'vsapi', 'EXPLORERBAR', 3, {
                             ('pressed', '!selected'): 3,
                             ('active', '!selected'): 2,
                             ('pressed', 'selected'): 6,
                             ('active', 'selected'): 5,
                             ('selected',): 4,
                             (): 1})

@serhiy-storchaka serhiy-storchaka added type-feature A feature request or enhancement 3.13 bugs and security fixes labels Oct 28, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Oct 29, 2023
* Remove mention of "vsapi" element type from the documentation.
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.
serhiy-storchaka added a commit that referenced this issue Nov 8, 2023
…1453)

* Remove mention of "vsapi" element type from the documentation.
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 8, 2023
…ythonGH-111453)

* Remove mention of "vsapi" element type from the documentation.
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.
(cherry picked from commit 005d1e8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 8, 2023
…ythonGH-111453)

* Remove mention of "vsapi" element type from the documentation.
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.
(cherry picked from commit 005d1e8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Nov 27, 2023
…GH-111453) (GH-111858)

* Remove mention of "vsapi" element type from the documentation.
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.

(cherry picked from commit 005d1e8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Nov 27, 2023
…GH-111453) (GH-111857)

* Remove mention of "vsapi" element type from the documentation.
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.
(cherry picked from commit 005d1e8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…ythonGH-111453)

* Remove mention of "vsapi" element type from the documentation.
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
…ythonGH-111453)

* Remove mention of "vsapi" element type from the documentation.
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes topic-tkinter type-bug An unexpected behavior, bug, or error type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants