Skip to main content

A collection of modern themes with code that makes it easy to integrate into a tkinter project.

Project description

TKinter Modern Themes

Tests Badge Python Version Badge License Badge

TKinter is a powerful UI library included in the python standard library. Unfortunately, it is hard to customize and looks ugly by default. This library contains a set of modern themes to improve the look of tkinter.

The themes in this library were developed by rdbende and licensed under the MIT license. https://github.com/rdbende This library fixes some naming consistency between these themes and adds simple logic for activating them.

This library also has code to implement WidgetFrames, an expansion on TKinter's label frames that make creating complex layouts much quicker and more readable.

Installation

pip install TKinterModernThemes

Why use themes?

Tkinter looks really ugly by default.

These themes look much better, and take the same amount of time to code because they don't need to be manually customized.

Included Themes

Each theme has a light and dark mode.

Park

Park is a modified version of Forest in order to make it consistent with the other themes. It is inspired by Excel.

Sun-valley

Sun-valley is designed to look like Windows 11.

Azure

Azure is similar to park, with a blue as the accent color.

All screenshots created by running allwidgets.py with different theme settings.

Integration

These themes can be added by creating a themed frame. A theme and mode (dark/light) can be specified.

The frame for the app can be accessed by self.root, but WidgetFrames provide a cleaner alternative.

Widget Frames

In this library, everything that supports adding widgets is a widget frame. Instead of creating a widget and later adding it to a frame, widget frames combine these steps. They also provide much better defaulting and doc strings then default tkinter.

Example:

import TKinterModernThemes as TKMT

def buttonCMD():
        print("Button clicked!")

class App(TKMT.ThemedTKinterFrame):
    def __init__(self):
        super().__init__("TITLE", "park", "dark")
        self.button_frame = self.addLabelFrame("Frame Label")
        self.button_frame.Button("Button Text", buttonCMD) #the button is dropped straight into the frame
        self.run()

App()

The widgets have params for the common use cases. If more params are needed, they can be passed as dicts to **widgetkwargs and **gridkwargs respectively.

WidgetFrames can be combined with normal tkinter use. Note: debugPrint() will only display widgets created from the WidgetFrame. Custom created widgets can be linked to the WidgetFrame by appending them to WidgetFrame.widgets.widgetlist (this also allows for overlap checking)

import TKinterModernThemes as TKMT
from TKinterModernThemes.WidgetFrame import Widget
from tkinter import ttk


def buttonCMD():
        print("Button clicked!")


class App(TKMT.ThemedTKinterFrame):
        def __init__(self, theme, mode, usecommandlineargs=True, usethemeconfigfile=True):
                super().__init__("TITLE", theme, mode, usecommandlineargs, usethemeconfigfile)
                self.Button("Auto placed button!", buttonCMD)  # placed at row 0, col 0

                self.button_frame = self.addLabelFrame("Frame Label")  # placed at row 1, col 0

                self.button_frame.Button("Button Text", buttonCMD)  # the button is dropped straight into the frame

                button = ttk.Button(self.button_frame.master, text="Button in frame!")
                button.grid(row=1, column=0, padx=10, pady=10, sticky='nsew')

                button = ttk.Button(self.master, text="Button outside frame!")
                button.grid(row=2, column=0, padx=10, pady=10, sticky='nsew')

                button = ttk.Button(self.master, text="debugPrint() finds this button")
                button.grid(row=3, column=0, padx=10, pady=10, sticky='nsew')
                self.widgets.widgetlist.append(Widget(button, "Button", 3, 0, 1, 1,
                                                      "debugPrint() finds this button"))
                self.debugPrint()
                self.run()


if __name__ == "__main__":
        App("park", "dark")

WidgetFrames adds new items to each column below the last placed item in that column. WidgetFrame.debugPrint() can be used to see how the widget is attempting to place each item. Items can be manually placed with the row and col params. If two items overlap, a warning will be printed upon widget creation.

Setting the theme:

The theme is set by default to "park" with mode "dark". This can be overrided with parameters in super().__init__()

  • title: Window title
  • theme: Main theme file. One of (azure / sun-valley / park). Defaults to park.
  • mode: Light or dark theme. One of (light / dark). Defaults to dark.
  • usecommandlineargs: If this is True (default), the frame checks for params passed into the script launch to grab a theme.
  • useconfigfile: If this is True (default), the frame checks for a file named themeconfig.json and seaches for theme and mode. Config files override command line args.
  • topLevel: If this is True (default = False), this window will be a topLevel window and inherit its theme and root from the main window. This is necessary if you have multiple windows.

By default, themeconfig.json overrides command line args, which overrides manually passed in themes, which override the defaults.

Example:

{
  "theme": "azure",
  "mode": "light"
}

Notebooks and Paned Windows

Notebooks and paned windows have been modified to include widget frame capabilities.

import TKinterModernThemes as TKMT

class App(TKMT.ThemedTKinterFrame):
    def __init__(self):
        super().__init__("TKinter Custom Themes Demo")
        
        self.panedWindow = self.PanedWindow("Paned Window Test")
        self.pane1 = self.panedWindow.addWindow() #pane1 is a widget frame

        self.notebook = self.pane1.Notebook("Notebook Test")
        self.tab1 = self.notebook.addTab("Tab Title") #tab1 is a widget frame

Resizable Windows

The main app will recursively resize all subframes. This can be turned off with the cleanresize param in run(). Only frames makes this resize only apply to frames that only have subframes, not widgets. This generally looks better, but can be disabled by setting onlyFrames to False.

Resizing can also be manually added to a frame by calling makeResizable().

New Widgets:

SlideSwitch

A variant of a checkbox that looks like a switch.

import TKinterModernThemes as TKMT
import tkinter as tk


class App(TKMT.ThemedTKinterFrame):
        def __init__(self, theme, mode, usecommandlineargs=True, usethemeconfigfile=True):
                super().__init__("Switch", theme, mode, usecommandlineargs=usecommandlineargs,
                                 useconfigfile=usethemeconfigfile)
                self.switchframe = self.addLabelFrame("Switch Frame")
                self.switchvar = tk.BooleanVar()
                self.switchframe.SlideSwitch("Switch", self.switchvar)
                self.run()


if __name__ == "__main__":
        App("park", "dark")

ToggleButton

A variant of a checkbox that looks like a button.

import TKinterModernThemes as TKMT
import tkinter as tk


class App(TKMT.ThemedTKinterFrame):
        def __init__(self, theme, mode, usecommandlineargs=True, usethemeconfigfile=True):
                super().__init__("Toggle button", theme, mode,
                                 usecommandlineargs=usecommandlineargs, useconfigfile=usethemeconfigfile)
                self.togglebuttonframe = self.addLabelFrame("Toggle Button Frame")
                self.togglebuttonvar = tk.BooleanVar()
                # Togglebutton
                self.togglebutton = self.togglebuttonframe.ToggleButton(text="Toggle button",
                                                                        variable=self.togglebuttonvar)
                self.run()


if __name__ == "__main__":
        App("park", "dark")

AccentButton

A button that has a default color of a clicked button.

import TKinterModernThemes as TKMT


def handleButtonClick():
        print("Button clicked!")


class App(TKMT.ThemedTKinterFrame):
        def __init__(self, theme, mode, usecommandlineargs=True, usethemeconfigfile=True):
                super().__init__("Accent button", theme, mode,
                                 usecommandlineargs=usecommandlineargs, useconfigfile=usethemeconfigfile)

                self.frame = self.addLabelFrame("Accent Button Frame")
                self.frame.AccentButton("Accent Button", handleButtonClick)
                self.run()


if __name__ == "__main__":
        App("park", "dark")

See allwidgets.py for info on each widget. See examples for more examples on using TKMT frames.

Matplotlib integration

TKMT can work with matplotlib. See WidgetFrame.matplotlibFrame for more info.

Example:

import TKinterModernThemes as TKMT
import random

class App(TKMT.ThemedTKinterFrame):
    def __init__(self): 
        super().__init__("Matplotlib Example")

        self.graphframe = self.addLabelFrame("2D Graph")
        self.graphframe2 = self.addLabelFrame("3D Graph", col=1)
        self.canvas, fig, self.ax, background, self.accent = self.graphframe.matplotlibFrame("Graph Frame Test")
        self.canvas2, fig2, self.ax2, _, _ = self.graphframe2.matplotlibFrame("Graph 3D", projection='3d')
        buttonframe = self.addLabelFrame("Control Buttons", colspan=2)
        buttonframe.Button("Add Data", self.addData)
        self.run()

    def addData(self):
        x = []
        y = []
        z = []

        for i in range(0, 100):
            for l in [x, y, z]:
                l.append(random.random() * 100)

        self.ax.scatter(x, y, c=self.accent)
        self.ax2.scatter(x, y, z, c=self.accent)
        self.canvas.draw()
        self.canvas2.draw()

if __name__ == "__main__":
    App()

Important Info for Executable Creation

If you are using tools like pyinstaller to make your python program into an .exe file, make sure you add --collect-data TKinterModernThemes to the command.

For example: pyinstaller --collect-data TKinterModernThemes main.py

If you are using auto-py-to-exe, you can add the library using the additional files option. (Add folder: venv/Lib/sitepackages/TKinterModernThemes)

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

tkintermodernthemes-1.10.5.tar.gz (712.6 kB view details)

Uploaded Source

Built Distribution

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

tkintermodernthemes-1.10.5-py3-none-any.whl (837.6 kB view details)

Uploaded Python 3

File details

Details for the file tkintermodernthemes-1.10.5.tar.gz.

File metadata

  • Download URL: tkintermodernthemes-1.10.5.tar.gz
  • Upload date:
  • Size: 712.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tkintermodernthemes-1.10.5.tar.gz
Algorithm Hash digest
SHA256 77c270a8bd8f41f42755f09946965732f865500eb9dda505d9680642fcd644c2
MD5 d88ed6b4e245a838d5b35d9fb43337fe
BLAKE2b-256 0fd2f8cb632fc150975f2fee0d9804d4a56e80e5896da72e2b1e408763ab5f27

See more details on using hashes here.

File details

Details for the file tkintermodernthemes-1.10.5-py3-none-any.whl.

File metadata

File hashes

Hashes for tkintermodernthemes-1.10.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8cad7529307647cc8789cfa1cafc60b1e9d9d41c62389b7246a943de99e61eb5
MD5 dae89701bbed11eaf5f06558968c2a22
BLAKE2b-256 98059828696af8fdd987f3bb88019a62f4f2cd6759ffd140ff2bc6234aeb4be1

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