Convert Figma logo to code with AI

rdbende logoSun-Valley-ttk-theme

A gorgeous theme for Tkinter/ttk, based on the Sun Valley visual style ✨

2,162
120
2,162
34

Top Related Projects

A modern and customizable python UI-library based on Tkinter

An easy and fast way to create a Python GUI 🐍

A supercharged theme extension for tkinter that enables on-demand modern flat style themes inspired by Bootstrap.

Quick Overview

The Sun-Valley-ttk-theme is a modern and elegant theme for Python's Tkinter GUI toolkit, specifically designed for ttk widgets. It provides a fresh, contemporary look inspired by Windows 11's UI design, offering both light and dark modes to enhance the visual appeal of Tkinter applications.

Pros

  • Offers a modern, visually appealing design that significantly improves the default Tkinter appearance
  • Supports both light and dark modes, allowing for better user customization
  • Compatible with various ttk widgets, providing a consistent look across the application
  • Easy to implement and integrate into existing Tkinter projects

Cons

  • Limited to ttk widgets, may not affect all elements of a Tkinter application
  • Requires additional setup and configuration compared to using default Tkinter themes
  • May not be fully compatible with all operating systems or Tkinter versions
  • Customization options beyond light/dark modes are limited

Code Examples

  1. Importing and applying the theme:
import tkinter as tk
from tkinter import ttk
import sv_ttk

root = tk.Tk()
sv_ttk.set_theme("light")  # or "dark"

# Your Tkinter code here

root.mainloop()
  1. Creating a themed button:
button = ttk.Button(root, text="Click me!")
button.pack(padx=20, pady=20)
  1. Switching between light and dark modes:
def toggle_theme():
    if sv_ttk.get_theme() == "dark":
        sv_ttk.set_theme("light")
    else:
        sv_ttk.set_theme("dark")

theme_button = ttk.Button(root, text="Toggle Theme", command=toggle_theme)
theme_button.pack(padx=20, pady=20)

Getting Started

To use the Sun-Valley-ttk-theme in your Tkinter project:

  1. Install the theme:

    pip install sv-ttk
    
  2. Import and apply the theme in your Python script:

    import tkinter as tk
    from tkinter import ttk
    import sv_ttk
    
    root = tk.Tk()
    sv_ttk.set_theme("light")  # or "dark"
    
    # Your Tkinter widgets and layout code here
    
    root.mainloop()
    
  3. Run your script, and enjoy the new modern look of your Tkinter application!

Competitor Comparisons

A modern and customizable python UI-library based on Tkinter

Pros of CustomTkinter

  • Offers a more modern and customizable UI with rounded corners and gradient effects
  • Provides additional custom widgets like CTkButton, CTkEntry, and CTkProgressBar
  • Supports both light and dark modes with easy theme switching

Cons of CustomTkinter

  • Requires additional dependencies (e.g., darkdetect, typing_extensions)
  • May have a steeper learning curve due to custom widget implementations
  • Less native look and feel compared to Sun-Valley-ttk-theme

Code Comparison

Sun-Valley-ttk-theme:

import tkinter as tk
from tkinter import ttk
import sv_ttk

root = tk.Tk()
sv_ttk.set_theme("dark")
button = ttk.Button(root, text="Click me!")
button.pack()
root.mainloop()

CustomTkinter:

import customtkinter as ctk

ctk.set_appearance_mode("dark")
root = ctk.CTk()
button = ctk.CTkButton(root, text="Click me!")
button.pack()
root.mainloop()

Both libraries aim to enhance the visual appeal of Tkinter applications, but they take different approaches. Sun-Valley-ttk-theme focuses on improving the native ttk widgets, while CustomTkinter introduces custom widget classes with additional styling options. The choice between the two depends on the specific requirements of your project and the desired look and feel of your application.

An easy and fast way to create a Python GUI 🐍

Pros of Tkinter-Designer

  • Provides a drag-and-drop interface for designing Tkinter GUIs
  • Generates Python code automatically from the design
  • Supports custom widgets and styling options

Cons of Tkinter-Designer

  • Limited to Tkinter's default appearance and widgets
  • Requires external design tool (Figma) for creating layouts
  • May produce less optimized code compared to manual implementation

Code Comparison

Sun-Valley-ttk-theme:

import tkinter as tk
from tkinter import ttk
import sv_ttk

root = tk.Tk()
sv_ttk.set_theme("dark")

button = ttk.Button(root, text="Styled Button")
button.pack()

root.mainloop()

Tkinter-Designer:

from tkinter import *
from tkinter import ttk

window = Tk()

btn = Button(window, text="Button")
btn.place(x=20, y=20, width=100, height=30)

window.mainloop()

Sun-Valley-ttk-theme focuses on enhancing the visual appearance of Tkinter applications with a modern theme, while Tkinter-Designer emphasizes rapid GUI development through visual design tools. Sun-Valley-ttk-theme provides a cohesive and polished look out-of-the-box, whereas Tkinter-Designer offers more flexibility in layout design but relies on Tkinter's default styling. The code comparison shows that Sun-Valley-ttk-theme requires minimal additional setup to apply its theme, while Tkinter-Designer generates standard Tkinter code based on the visual design.

A supercharged theme extension for tkinter that enables on-demand modern flat style themes inspired by Bootstrap.

Pros of ttkbootstrap

  • More comprehensive theming system with a wider variety of styles and color schemes
  • Includes additional custom widgets beyond standard ttk offerings
  • Better documentation and examples for easier implementation

Cons of ttkbootstrap

  • Larger file size and potentially higher resource usage
  • May have a steeper learning curve for beginners due to more options and features

Code Comparison

Sun-Valley-ttk-theme:

import tkinter as tk
from tkinter import ttk
import sv_ttk

root = tk.Tk()
sv_ttk.set_theme("dark")

ttkbootstrap:

import ttkbootstrap as ttk
from ttkbootstrap.constants import *

root = ttk.Window(themename="darkly")

The Sun-Valley-ttk-theme uses a simpler approach to set the theme, while ttkbootstrap offers more customization options and a dedicated Window class. ttkbootstrap also provides constants for easier styling and layout management.

Both libraries aim to enhance the visual appeal of Tkinter applications, but ttkbootstrap offers a more extensive set of features and customization options at the cost of increased complexity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Sun Valley ttk theme

Make your Tkinter application look better than ever with just two lines of code!

Screenshot of Sun Valley ttk theme

Installation PyPi downloads

The theme is easily installable as a Python package

pip install sv-ttk

Usage Documentation

[!NOTE] The theme will only be applied to themable (tkinter.ttk) widgets, and not with the regular Tkinter widgets, they only benefit from the colorscheme.

For detailed documentation, visit the wiki page.

import tkinter
from tkinter import ttk

import sv_ttk

root = tkinter.Tk()

button = ttk.Button(root, text="Click me!")
button.pack()

# This is where the magic happens
sv_ttk.set_theme("dark")

root.mainloop()

Tips and tricks

Our intention is to keep the sv-ttk package as simple as possible, while making it easy to integrate with other libraries.

Set the theme to the system theme

You can use the darkdetect package to detect the system color scheme. Here's an example:

import darkdetect

sv_ttk.set_theme(darkdetect.theme())

It's only a matter of an extra import and passing the result of darkdetect.theme() to sv_ttk.set_theme(). It's that easy!

Dark mode title bar on Windows

The Sun Valley theme doesn't change the title bar color on Windows when the theme is set to dark. You can use pywinstyles to achieve this. Here's an example:

import pywinstyles, sys

def apply_theme_to_titlebar(root):
    version = sys.getwindowsversion()

    if version.major == 10 and version.build >= 22000:
        # Set the title bar color to the background color on Windows 11 for better appearance
        pywinstyles.change_header_color(root, "#1c1c1c" if sv_ttk.get_theme() == "dark" else "#fafafa")
    elif version.major == 10:
        pywinstyles.apply_style(root, "dark" if sv_ttk.get_theme() == "dark" else "normal")

        # A hacky way to update the title bar's color on Windows 10 (it doesn't update instantly like on Windows 11)
        root.wm_attributes("-alpha", 0.99)
        root.wm_attributes("-alpha", 1)

# Example usage (replace `root` with the reference to your main/Toplevel window)
apply_theme_to_titlebar(root)

Note that on Windows 10, due to its limitations, you can only set the title bar's color to black for dark mode and white for light mode. On Windows 11 the title bar can be set to any color.

[!WARNING] The apply_theme_to_titlebar works on Windows only, so you should check whether the platform is Windows before calling this function.

Here's how the windows look after calling set_title_bar_color():

Screenshots

Windows 10


Windows 11

Wanna see more?

Check out my other ttk themes!