CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

CTkSwitch appearance in DarkMode

Open Snute93 opened this issue 3 years ago • 4 comments

Code:

import tkinter
import tkinter.messagebox
import customtkinter

customtkinter.set_appearance_mode("Light")  # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("dark-blue")  # Themes: "blue" (standard), "green", "dark-blue"


class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()


        customtkinter.CTkButton(master=self, height=300).grid(row=0, column=0, sticky='nsew', pady=20, padx=20)
        customtkinter.CTkSwitch(master=self).grid(row=0, column=2, sticky='nsew', pady=20, padx=20)

        self.after(100, lambda: customtkinter.set_appearance_mode("Dark"))


if __name__ == "__main__":
    app = App()
    app.mainloop()

My result under macOS 13.1 and CTk 5.03: grafik

Snute93 avatar Dec 15 '22 17:12 Snute93

I will have a look!

TomSchimansky avatar Dec 15 '22 23:12 TomSchimansky

@Snute93 Do not use sticky="nswe" for switch, ig it is a bug. (Use only "new")

Akascape avatar Dec 16 '22 06:12 Akascape

Wow, thanks for the fast response! 'new' did work to make the bright rectangle disappear. For now I did apply the same height to Button and Switch. This way the switch is also vertically centered

Snute93 avatar Dec 16 '22 08:12 Snute93

It's now fixed.

One tip, you should save the widgets you create in variables, otherwise you cannot do anything with them and they can get garbage collected and disappear at some point:

import customtkinter

customtkinter.set_appearance_mode("light")  # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("dark-blue")  # Themes: "blue" (standard), "green", "dark-blue"


class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()

        self.button = customtkinter.CTkButton(master=self, height=300)
        self.button.grid(row=0, column=0, sticky='nsew', pady=20, padx=20)

        self.switch = customtkinter.CTkSwitch(master=self)
        self.switch.grid(row=0, column=1, sticky='nsew', pady=20, padx=20)

        self.after(100, lambda: customtkinter.set_appearance_mode("dark"))


if __name__ == "__main__":
    app = App()
    app.mainloop()

TomSchimansky avatar Jan 21 '23 13:01 TomSchimansky

Thanks for the advise. Actually I just tried to replicate the problem as simple as possible ;)

And most important: Thanks for looking into it and fixing it!

Snute93 avatar Jan 22 '23 21:01 Snute93