import tkinter as tk from tkinter import ttk root = tk.Tk() # Pack a big frame so, it behaves like the window background big_frame = ttk.Frame(root) big_frame.pack(fill="both", expand=True) # Set the initial theme root.tk.call("source", "sun-valley.tcl") root.tk.call("set_theme", "light") 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") # Remember, you have to use ttk widgets button = ttk.Button(big_frame, text="Change theme!", command=change_theme) button.pack() root.mainloop()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter