-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.py
70 lines (57 loc) · 2.55 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import tkinter as tk
from tkinter import ttk
import sun_valley_titlebar
from ctypes import windll, c_char_p, c_int, byref, sizeof
WINDOW_TITLE = "Titlebar Demo"
WINDOW_MINSIZE = (400, 400)
WINDOW_POSITION = (100, 100) # Make sure to set a decent starting position, otherwise the window will be placed at the top left of the screen
root = tk.Tk()
root.overrideredirect(True) # Make sure that overrideredirect is set to True
# Set window parameters
root.minsize(WINDOW_MINSIZE[0], WINDOW_MINSIZE[1])
root.geometry(str(WINDOW_MINSIZE[0]) + "x" + str(WINDOW_MINSIZE[1]) + "+" + str(WINDOW_POSITION[0]) + "+" + str(WINDOW_POSITION[1]))
root.title(WINDOW_TITLE)
# Set the default theme
root.tk.call("source", "sun-valley.tcl")
root.tk.call("set_theme", "light")
# Optional icon for the titlebar
# Must be a gif file and not too large
# because it currently is not automatically resized
icon = tk.PhotoImage(file='feather.gif')
# Change theme function
def change_theme():
if root.tk.call("ttk::style", "theme", "use") == "sun-valley-dark":
root.tk.call("set_theme", "light")
windll.dwmapi.DwmSetWindowAttribute(windll.user32.GetParent( root.winfo_id()), 20, byref(c_int(0)), sizeof(c_int(0)))
root.update()
root.withdraw()
root.deiconify()
else:
root.tk.call("set_theme", "dark")
windll.dwmapi.DwmSetWindowAttribute(windll.user32.GetParent( root.winfo_id()), 20, byref(c_int(2)), sizeof(c_int(2)))
root.update()
root.withdraw()
root.deiconify()
# Create the content frame
big_frame = ttk.Frame(root)
# Create the titlebar
# Parameters: master, big_frame (for resizing), icon, title, minimize button?, maximize button?, close button?, min window size x, min window size y
titlebar = sun_valley_titlebar.Titlebar(root, big_frame, icon, WINDOW_TITLE, True, True, True, WINDOW_MINSIZE[0], WINDOW_MINSIZE[1])
# Create a menubar
menubar = sun_valley_titlebar.Menubar(root)
# Add "File" menu to the menubar
menu = sun_valley_titlebar.Menu(menubar, "File")
menu.add_command("Change theme", change_theme)
menu.add_separator()
menu.add_command("Exit", root.destroy)
# Add "Options" menu to the menubar
options_menu = sun_valley_titlebar.Menu(menubar, "Options")
options_menu.add_command("Option 1")
options_menu.add_command("Option 2")
options_menu.add_command("Option 3")
# Finally pack the big frame so it is below the titlebar and menu
big_frame.pack(fill="both", expand=True)
# Content goes here, with master = big_frame
button = ttk.Button(big_frame, text="Change theme!", command=change_theme)
button.pack()
root.mainloop()