How to change theme to tkinter: get the Sun Valley theme

A Windows inspired theme for tkinter.

Tkinter is the module to use GUI with python’s app. This theme makes tkinter nicer.

import tkinter as tk
from tkinter import ttk


def click_theme():
    global root
    # WHEN CLICK IF THE THEME IS DARK IT SET TO LIGHT
    is_dark = root.tk.call("ttk::style", "theme", "use") == "sun-valley-dark"
    root.tk.call("set_theme", "light") if is_dark else root.tk.call("set_theme", "dark")

def window():
    global root

    root = tk.Tk()
    # CALLING THE THEME
    root.tk.call("source", "sun-valley.tcl")
    root.tk.call("set_theme", "light")

    # THE FRAME FOR THE BUTTON
    big_frame = ttk.Frame(root)
    big_frame.pack(fill="both", expand=True)
    # THE TTK BUTTON CALLING click_theme to change theme
    button = ttk.Button(big_frame, text="Change theme!", command=click_theme)
    button.pack()

    root.mainloop()

window()

light theme
ttk tkinter theme sun valley
dark theme

https://github.com/formazione/SunValleyttktheme


Subscribe to the newsletter for updates
Tkinter templates

Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Claude's Games

Arkanoid
Platform 2d

1. Memory game

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Advertisement