israel-dryer / ttkbootstrap

A supercharged theme extension for tkinter that enables on-demand modern flat style themes inspired by Bootstrap.
MIT License
1.98k stars 393 forks source link

cannot use configure() to change style of widgets #594

Open Ice-pumpkin opened 4 months ago

Ice-pumpkin commented 4 months ago

Desktop (please complete the following information):

ttkbootstrap Version - 1.10.1

OS - Windows 11 24H2

Describe the bug

when using configure to change style, I receives the following error:

Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python312\Lib\tkinter__init.py", line 1968, in call return self.func(*args) ^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\Desktop\Real-time-Face-Recognition-using-OpenCV\Repeat bug.py", line 6, in change myLabel.configure(style=f'{PRIMARY}') File "C:\Users\Lenovo\Desktop\Real-time-Face-Recognition-using-OpenCV\venv\Lib\site-packages\ttkbootstrap\style.py", line 5003, in configure func(self, cnf, **kwargs) File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python312\Lib\tkinter__init__.py", line 1722, in configure return self._configure('configure', cnf, kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python312\Lib\tkinter\init__.py", line 1712, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) _tkinter.TclError: Layout primary not found

To Reproduce

import ttkbootstrap as ttk from ttkbootstrap.constants import *

def change(): myLabel.configure(style=f'{SECONDARY}')

change font works fine: myLabel.configure(font=("Segoe UI", 23))

# change text works fine:       myLabel.configure(font=(text="I am changed")
# change foreground works fine: myLabel.configure(foreground="BLUE")

window = ttk.Window("TestGUI", themename="litera", size=(400, 400))

myFrame = ttk.Frame(window) myFrame.grid(padx=150, pady=150)

myButton = ttk.Button(myFrame, text="Button", command=change) myButton.grid(row=0)

myLabel = ttk.Label(myFrame, text="Label", style=f'{PRIMARY}') myLabel.grid(row=1)

window.mainloop()

Expected behavior

When clicking myButton, the color of myLabel should change from "primary" to "secondary".

Screenshots

No response

Additional context

No response