Skip to main content

Use the Sun Valley ttk theme with a Python module

Project description

Sun Valley ttk theme


A stunning theme for ttk based on Microsoft's Sun Valley visual styles

Screenshot

Installation

The theme is easily installable as a Python package

pip install sv-ttk

Usage

import tkinter as tk
import sv_ttk

root = tk.Tk()

sv_ttk.set_theme("light")  # Set light theme
sv_ttk.set_theme("dark")  # Set dark theme

sv_ttk.use_light_theme()  # Set light theme
sv_ttk.use_dark_theme()  # Set dark theme

sv_ttk.toggle_theme()  # Toggle between dark and light theme

print(sv_ttk.get_theme())  # Get what theme the app uses (either 'light' or 'dark')

root.mainloop()

Usage with Tcl/Tk

To make setting the theme and the right colours as easy as possible, there is a separate script that handles all this. This way whether you want to use a dark or light theme, you need to import just a single file, and the colors will be configured even for non-ttk widgets for a consistent look.

source sun-valley.tcl

set_theme light  ;# Set light theme
# or
set_theme dark  ;# Set dark theme

Switching themes

Normally changing between themes isn't that easy, because then the colors doesn't get configured correctly. See this SO question. However, with my current solution, you can change theme at any time, without any color issues.

package require Tk 8.6
source "sun-valley.tcl"

set_theme light

# Pack a big frame so, it behaves like the window background
ttk::frame .big_frame
pack .big_frame -fill both -expand 1

proc changeTheme {} {
    # NOTE: The theme's real name is sun-valley-<mode>
    if {[ttk::style theme use] == "sun-valley-dark"} {
        # Set light theme
        set_theme light
    } else {
        # Set dark theme
        set_theme dark
    }
}

ttk::button .big_frame.button -text "Change theme!" -command changeTheme
pack .big_frame.button

Bugs

  • Tk isn't really good at displaying png images, so if your program is laggy with the theme, please check out the gif-based branch! (hasn't been updated for a while)
  • When you change the theme, and your app has a treeview, the window resizes. This is a quite strange bug that applies to other ttk themes too.

Examples

I made a separate repo for the examples: Sun-Valley-ttk-examples. Be sure to star and watch it because I might make some more examples, with awesome tips and tricks!

What's next?

Check out my other ttk themes!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sv_ttk-1.0.tar.gz (67.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sv_ttk-1.0-py3-none-any.whl (103.6 kB view details)

Uploaded Python 3

File details

Details for the file sv_ttk-1.0.tar.gz.

File metadata

  • Download URL: sv_ttk-1.0.tar.gz
  • Upload date:
  • Size: 67.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for sv_ttk-1.0.tar.gz
Algorithm Hash digest
SHA256 dc8c92d27f23d66337cbc2b35dddac01d79200dab2b2f6440a6e78c2273b7219
MD5 0d7f8cb4664736bff2b8ffe8976cb3ac
BLAKE2b-256 ca2464490fccc992d61c8284005786e140bd2d0294da1086c44af3f88dc95cd6

See more details on using hashes here.

File details

Details for the file sv_ttk-1.0-py3-none-any.whl.

File metadata

  • Download URL: sv_ttk-1.0-py3-none-any.whl
  • Upload date:
  • Size: 103.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for sv_ttk-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ed2b88307bcd815c077e3e50d6a611c4455f6477a519b7a54226925bf371625
MD5 1d80071d1875eee09a580d9039a4f1f1
BLAKE2b-256 d613640087c44e50f751242fef65d2773ff16c9f415a785c5b30b57f5da4b4ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page