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"source", "sun-valley.tcl")"set_theme", "light")

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

# Remember, you have to use ttk widgets
button = ttk.Button(big_frame, text="Change theme!", command=change_theme)

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