Problem with Tkinter ttk theme in changing between light and dark (UI automatically scale)

Viewed 358

i'm using Python and Tkinter for GUI. I've a function using switch and ttk for switching between light and dark mode:

def ThemeChanger():
    if screen.tk.call("ttk::style", "theme", "use") == "sun-valley-dark":
        # Set light theme
        screen.tk.call("set_theme", "light")
    else:
        # Set dark theme
        screen.tk.call("set_theme", "dark"

But when I clicked into the switch, all the UI automatically scales a litter bit:

Light Mode

Dark Mode

It will scale larger if i use tabs or table in ttk Tkinter, and won't scale back when switch to light mode, it scales more and more when I clicked into theme switch button:

def change_theme():
    # NOTE: The theme's real name is sun-valley-<mode>
    if root.tk.call("ttk::style", "theme", "use") == "sun-valley-dark":
        # Set light theme
        root.tk.call("set_theme", "light")
    else:
        # Set dark theme
        root.tk.call("set_theme", "dark")

Unchange

1st change

2nd change

3rd change

4th change

I don't know how to fix this. I would so appreciate if anyone can recommend me improving these. Thank you!

1 Answers

I partially fixed this bug, see this. But the Treeview still scales, and I can't figure out, why. This strange problem applies to all third-party ttk themes that have some kind of treeview styling, but not to others.

Related