106 lines
3.2 KiB
Python
106 lines
3.2 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
from components import *
|
|
|
|
|
|
class Page1:
|
|
def __init__(self, root, top_options, bottom_options):
|
|
self.root = root
|
|
self.top_options = top_options
|
|
self.bottom_options = bottom_options
|
|
|
|
# ========== 顶部复选框区域 ==========
|
|
self.top_frame = tk.Frame(self.root, bg=BG_COLOR, pady=25)
|
|
self.top_frame.pack(side=tk.TOP, fill=tk.X)
|
|
|
|
self.top_vars = []
|
|
for option in top_options:
|
|
var = tk.BooleanVar(value=True)
|
|
chk = ttk.Checkbutton(self.top_frame, text=option, variable=var, style="Custom.TCheckbutton")
|
|
chk.pack(side=tk.LEFT, padx=20)
|
|
self.top_vars.append(var)
|
|
|
|
# ========== 分割线 ==========
|
|
separator = tk.Frame(self.root, height=1, bg="black")
|
|
separator.pack(side=tk.TOP, fill=tk.X, padx=20)
|
|
|
|
# ========== 底部复选框区域 ==========
|
|
self.bottom_frame = tk.Frame(self.root, bg=BG_COLOR, pady=25)
|
|
self.bottom_frame.pack(side=tk.TOP, fill=tk.X)
|
|
|
|
self.bottom_vars = []
|
|
for option in bottom_options:
|
|
var = tk.BooleanVar(value=True)
|
|
chk = ttk.Checkbutton(self.bottom_frame, text=option, variable=var, style="Custom.TCheckbutton")
|
|
chk.pack(side=tk.LEFT, padx=20)
|
|
self.bottom_vars.append(var)
|
|
|
|
# ========== 说明文本区域 ==========
|
|
text_frame = tk.Frame(self.root, bg=BG_COLOR)
|
|
text_frame.pack(side=tk.TOP, padx=40, pady=10, fill=tk.X)
|
|
|
|
text_widget = tk.Text(
|
|
text_frame,
|
|
height=6,
|
|
width=60,
|
|
wrap=tk.WORD,
|
|
bg=BG_COLOR,
|
|
fg=FG_COLOR,
|
|
relief=tk.FLAT,
|
|
borderwidth=0,
|
|
font=(FONT_FAMILY, 12),
|
|
padx=10,
|
|
pady=10
|
|
)
|
|
text_widget.pack(expand=True, fill=tk.X)
|
|
text_widget.insert(tk.END, instructions)
|
|
text_widget.config(state=tk.DISABLED)
|
|
|
|
def setup_styles(self):
|
|
"""设置 ttk 样式"""
|
|
|
|
|
|
def top_selected(self):
|
|
"""返回第一行中被选中的项"""
|
|
return [opt for opt, var in zip(self.top_options, self.top_vars) if var.get()]
|
|
|
|
def bottom_selected(self):
|
|
"""返回第二行中被选中的项"""
|
|
return [opt for opt, var in zip(self.bottom_options, self.bottom_vars) if var.get()]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
top_options = ["1", "2", "3", "4"]
|
|
bottom_options = ["全部的题", "未做过的题", "错过的题", ]
|
|
|
|
root = tk.Tk()
|
|
app = Page1(root, top_options, bottom_options)
|
|
|
|
# 按钮区域
|
|
button_frame = tk.Frame(root)
|
|
button_frame.pack(side=tk.TOP, pady=20)
|
|
|
|
# 打印上一行选中项的按钮
|
|
btn_print_top = tk.Button(
|
|
button_frame,
|
|
text="1",
|
|
command=lambda: print(app.top_selected()),
|
|
font=("Helvetica", 14),
|
|
bg="lightblue",
|
|
width=20
|
|
)
|
|
btn_print_top.pack(side=tk.LEFT, padx=10)
|
|
|
|
# 打印下一行选中项的按钮
|
|
btn_print_bottom = tk.Button(
|
|
button_frame,
|
|
text="2",
|
|
command=lambda: print(app.bottom_selected()),
|
|
font=("Helvetica", 14),
|
|
bg="lightgreen",
|
|
width=20
|
|
)
|
|
btn_print_bottom.pack(side=tk.LEFT, padx=10)
|
|
|
|
root.mainloop()
|