rdbende / Sun-Valley-ttk-theme

A gorgeous theme for Tkinter/ttk, based on the Sun Valley visual style ✨
https://pypi.org/project/sv-ttk
MIT License
1.98k stars 112 forks source link

Theme/style not applied to Toplevel Widget #128

Open Aesonus opened 9 months ago

Aesonus commented 9 months ago

After updating to version 2.6 it appears that the theme is no longer being applied to Toplevel widgets.

Using the following code:

import tkinter as tk
from tkinter import ttk

import sv_ttk

root = tk.Tk()
sv_ttk.use_light_theme()

toplevel = tk.Toplevel(root)
toplevel.title("Test Toplevel")
ttk.Label(toplevel, text="Hello, world!").pack()
ttk.Button(toplevel, text="Close", command=root.quit).pack()
toplevel.protocol("WM_DELETE_WINDOW", root.quit)

root.withdraw()
root.mainloop()

On version 2.6 it looks like this (wrong): bad-window

On version 2.5.5 (correct): good-window

This is on a Windows 11 system. I have not tested it yet on any other OS, so I am not sure if this is a problem for them too, or just Windows 11.

EDIT: I did test the Tk widget and the styles are applied correctly to widgets in it.

EDIT 2: It also looks like if there is a ttk widget added to the Tk widget, then the TopLevel displays correctly:

littlewhitecloud commented 9 months ago

It was caused by #113, I just tested it. That's strange, I test a lot but can not fix it.

Aesonus commented 9 months ago

I think it may have something to do with the event propogation. If I do:

root.after(10, sv_ttk.use_light_theme)

Then everything works.