1
This commit is contained in:
91
main.py
Normal file
91
main.py
Normal file
@@ -0,0 +1,91 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from backend import Backend
|
||||
from components import *
|
||||
|
||||
# 后端
|
||||
c_backend = Backend()
|
||||
|
||||
# 创建主窗口
|
||||
root = tk.Tk()
|
||||
root.title("zrx")
|
||||
root.geometry("1000x900")
|
||||
root.configure(bg=BG_COLOR)
|
||||
|
||||
# 字体文件
|
||||
fonts = Fonts()
|
||||
|
||||
notebook = ttk.Notebook(root)
|
||||
notebook.pack(fill='both', expand=True, padx=10, pady=10)
|
||||
|
||||
style = ttk.Style()
|
||||
style.theme_use("winnative")
|
||||
|
||||
# 自定义复选框样式
|
||||
style.configure(
|
||||
"Custom.TCheckbutton",
|
||||
font=(FONT_FAMILY, 14),
|
||||
background=BG_COLOR,
|
||||
foreground=FG_COLOR,
|
||||
padding=8
|
||||
)
|
||||
style.map(
|
||||
"Custom.TCheckbutton",
|
||||
background=[("active", BG_COLOR)],
|
||||
foreground=[("active", ACCENT_COLOR)]
|
||||
)
|
||||
|
||||
# 页面0
|
||||
frame0 = ttk.Frame(notebook, padding=20)
|
||||
notebook.add(frame0, text="主页")
|
||||
page0 = Page0(frame0,fonts,c_backend)
|
||||
page0.init()
|
||||
|
||||
# 页面1
|
||||
frame1 = ttk.Frame(notebook, padding=20)
|
||||
notebook.add(frame1, text="设置")
|
||||
top_options = c_backend.get_source_type()
|
||||
page1 = Page1(frame1,top_options,bottom_options)
|
||||
|
||||
# 页面2
|
||||
frame2 = ttk.Frame(notebook, padding=20)
|
||||
notebook.add(frame2, text="统计")
|
||||
page2 = Page2(frame2)
|
||||
|
||||
# 事件
|
||||
def page0_event():
|
||||
c_backend.reset_time()
|
||||
c_backend.set_config(
|
||||
page1.top_selected(),
|
||||
page1.bottom_selected()
|
||||
)
|
||||
|
||||
def page1_event():
|
||||
pass
|
||||
|
||||
def page2_event():
|
||||
r = c_backend.get_statistics()
|
||||
print(r)
|
||||
page2.update_data(r)
|
||||
|
||||
tab_handlers = [
|
||||
page0_event,
|
||||
page1_event,
|
||||
page2_event,
|
||||
]
|
||||
|
||||
def on_space_pressed(event):
|
||||
page0.init()
|
||||
|
||||
def on_tab_changed(event):
|
||||
try:
|
||||
tab_handlers[notebook.index("current")]()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
# 绑定事件
|
||||
root.bind('<space>', on_space_pressed)
|
||||
notebook.bind("<<NotebookTabChanged>>", on_tab_changed)
|
||||
|
||||
# 运行主循环
|
||||
root.mainloop()
|
||||
Reference in New Issue
Block a user