This repository provides an easy way to create a custom titlebar that matches rdbende's Sun Valley ttk theme. Windows only for right now, it relies on windll to interact with the window manager.
See example.py for a demo
- Download the code and place it in your project. You must use the version of the Sun Valley theme provided here or at my fork of the Sun Valley repository (https://github.com/PicoPlanetDev/Sun-Valley-ttk-theme) or in this pull request (rdbende/Sun-Valley-ttk-theme#5) until the pull request is approved.
- Import tkinter and ttk
- Import sun_valley_titlebar
- Create your tkinter window, making sure a minsize is set and overrideredirect is True
- Set your theme
- If you want an icon, define a tkinter PhotoImage to hold the icon
- Create a content frame, but don't pack it yet
- Create a titlebar (see syntax below)
- (Optional) Create a menubar and add menus, commands, and separators (see syntax below)
- Pack the content frame with fill="Both" and expand="True"
- Add any content you want in the window to the content frame
- Run the mainloop
titlebar = sun_valley_titlebar.Titlebar(
<ROOT FRAME>, <CONTENT FRAME>, <ICON>, <TITLEBAR TEXT>, <MINIMIZE BUTTON?>, <MAXIMIZE BUTTON?>, <CLOSE BUTTON>, <MINSIZE X>, <MINSIZE Y>
)
To create the Menubar frame:
menubar = sun_valley_titlebar.Menubar(<ROOT FRAME>)
To add menus:
menu = sun_valley_titlebar.Menu(<MENUBAR OBJECT FROM ABOVE>, <STR MENU HEADER>)
To add commands and separators to a menu:
menu.add_command("Exit", root.destroy) # Add a command to exit the program
menu.add_separator() # Add a menu separator
- Add rounded corner background (files with correct colors and 8px corner radius are already included)
- Fix a bug where sometimes (ugh) the window won't re-appear after being minimized
If you complete any of these items, add a pull request and I'll happily include it!
Based on code from the following repositories:
https://github.com/rdbende/Sun-Valley-ttk-theme
https://github.com/Terranova-Python/Tkinter-Menu-Bar
Feather icon from Icons8: https://icons8.com/icon/FqJJi4fvAZtu/lightweight"