[Python] syntax error with ttk.Style.element_create()

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    Tying to understand the ttk, style element_create() syntax. Here is one that I copied off the internet, but it syntaxes.

    import tkinter as tk
    from tkinter import ttk

    root = tk.Tk()

    # Create a style
    style = ttk.Style()
    style.element_create("pin", "vsapi", "EXPLORERBAR", 3,
    ("pressed", "!selected"), 3,
    ("active", "!selected"), 2,
    ("pressed", "selected"), 6,
    ("active", "selected"), 5,
    ("selected",), 4,
    ("",), 1)

    style.layout("Explorer.Pin", [("Explorer.Pin.pin", {"sticky": "news"})])

    # Create a checkbutton with the custom style
    pin_checkbutton = ttk.Checkbutton(root, style="Explorer.Pin")
    pin_checkbutton.pack()

    root.mainloop()


    Traceback (most recent call last):
    File "C:/Python310/elementcreate2.py", line 8, in <module>
    style.element_create("pin", "vsapi", "EXPLORERBAR", 3,
    File "C:\Python310\lib\tkinter\ttk.py", line 459, in element_create
    spec, opts = _format_elemcreate(etype, False, *args, **kw)
    File "C:\Python310\lib\tkinter\ttk.py", line 132, in _format_elemcreate
    statemap = _join(_mapdict_values(args[2:]))
    File "C:\Python310\lib\tkinter\ttk.py", line 83, in _mapdict_values
    for *state, val in items:
    TypeError: cannot unpack non-iterable int object


    I've looked and looked for examples of proper syntax for this function, but can't seem to find one that works. What is the proper syntax for this function?

    Please help...

    Trying to code the element_create function syntax error free.

    Tried several different approaches (sample above) all give syntax error that I can't seem to correct.

    Continue reading...

Compartilhe esta Página