-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (51 loc) · 2.75 KB
/
main.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
# import statements
from tkinter import *
from tkinter import ttk
from functools import partial
import json
from functions import check_theme_json_file, center, calculator, threading, help, website, about, change_theme, update_theme
from init_appdata import appdata_folder
# home page
home = Tk()
home.iconbitmap('logo.ico')
home.title("Home Loan Calculator")
home.resizable(0, 0)
# this main frame is needed as a solution of theme changings in the sun valley theme: https://github.com/rdbende/Sun-Valley-ttk-theme#switching-themes
main_frame = ttk.Frame(home)
main_frame.pack(fill="both", expand=True, ipady=10)
# app name
ttk.Label(main_frame, text="Home Loan Calculator", font=("-family", "Segoe Print", "-size", 30),).grid(row=0, column=0, columnspan=2, padx=10)
ttk.Label(main_frame, text="by Jack Yeo", font=("-family", "Segoe Print", "-size", 15),).grid(row=1, column=0, columnspan=2)
# frame for main functions: calculator and results
home_frame = ttk.LabelFrame(main_frame, text="Home", padding=(20, 10))
home_frame.grid(row=2, column=0, padx=10, pady=5, sticky="e")
# about frame for about, link to website, and also help
about_frame = ttk.LabelFrame(main_frame, text="About", padding=(20, 10))
about_frame.grid(row=2, column=1, rowspan=2, padx=10, pady=5, sticky="w")
# settings frame for changing themes: light or dark mode
settings_frame = ttk.LabelFrame(main_frame, text="Settings", padding=(20, 10))
settings_frame.grid(row=3, column=0, padx=10, pady=5, sticky="e")
# pack the widgets for home and about frame
ttk.Button(home_frame, text = "Calculator", command = partial(calculator, home), style="Accent.TButton").pack(pady=5)
ttk.Button(home_frame, text = "Results", command = partial(threading, home), style="Accent.TButton").pack(pady = 5)
ttk.Button(about_frame, text = "About", command = partial(about, home)).pack(pady = 5)
ttk.Button(about_frame, text = "Website", command = website).pack(pady = 5)
ttk.Button(about_frame, text = "Help", command = partial(help, home)).pack(pady = 5)
if check_theme_json_file():
with open(f"{appdata_folder}/theme.json", "r") as theme_json_file:
theme = json.load(theme_json_file)["theme"]
else:
theme = "light"
update_theme(theme)
checked = BooleanVar(value=0 if theme == "light" else 1)
home.call("source", "sun-valley.tcl")
home.call("set_theme", theme)
# pack the dark mode checkbutton
ttk.Checkbutton(settings_frame, text="Dark theme", command=partial(change_theme, home), style="Switch.TCheckbutton", variable=checked).pack(pady=5)
# make all buttons' width 15
for widget in home_frame.winfo_children() + about_frame.winfo_children() + settings_frame.winfo_children():
if isinstance(widget, ttk.Button):
widget['width'] = 15
# center the window once home page when widgets are loaded
center(home)
home.mainloop()