窗口自适应

This commit is contained in:
zhangyuheng 2024-10-19 00:42:09 +08:00
parent 18d0cefe0b
commit 878686faf7

View File

@ -79,10 +79,20 @@ class ExamApp:
def init_exam_screen(self):
self.clear_screen()
# 左边显示考题
left_frame = tk.Frame(self.root, borderwidth=2, relief=tk.GROOVE, width=450, height=600)
left_frame.pack(side=tk.LEFT, padx=20, pady=20)
left_frame = tk.Frame(self.root, borderwidth=2, relief=tk.GROOVE)
left_frame.pack(side=tk.LEFT, padx=20, pady=20, fill=tk.BOTH, expand=True)
left_frame.pack_propagate(False)
# 上一题、下一题按钮
page_frame = tk.Frame(left_frame)
self.prev_btn = tk.Button(page_frame, text="上一题", command=lambda: self.jump_to_question(self.current_quest_index - 1))
self.prev_btn.pack(side=tk.LEFT, padx=20, pady=20, anchor=tk.NW)
self.next_btn = tk.Button(page_frame, text="下一题", command=lambda: self.jump_to_question(self.current_quest_index + 1))
self.next_btn.pack(side=tk.LEFT, padx=20, pady=20, anchor=tk.NE)
exit_btn = tk.Button(page_frame, text="退出", command=self.init_main_menu)
exit_btn.pack(side=tk.RIGHT, padx=20, pady=20, anchor=tk.NE)
page_frame.pack(fill=tk.X)
self.question_label = tk.Label(left_frame, text="", width=400, wraplength=400, anchor=tk.W
, justify=tk.LEFT, font=font
, borderwidth=2, relief=tk.GROOVE)
@ -103,16 +113,10 @@ class ExamApp:
self.correct_answer_label.pack(pady=20, padx=20)
self.correct_answer_label.pack_propagate(False)
# 上一题、下一题按钮
self.prev_btn = tk.Button(left_frame, text="上一题", command=lambda: self.jump_to_question(self.current_quest_index - 1))
self.prev_btn.pack(side=tk.LEFT, padx=20, pady=20, anchor=tk.NW)
self.next_btn = tk.Button(left_frame, text="下一题", command=lambda: self.jump_to_question(self.current_quest_index + 1))
self.next_btn.pack(side=tk.RIGHT, padx=20, pady=20, anchor=tk.NE)
# 右边显示考试状态
right_frame = tk.Frame(self.root, borderwidth=2, relief=tk.GROOVE, width=300, height=600)
right_frame.pack(side=tk.RIGHT, padx=20, pady=20)
right_frame = tk.Frame(self.root, borderwidth=2, relief=tk.GROOVE, width=300)
right_frame.pack(side=tk.RIGHT, padx=20, pady=20, fill=tk.Y)
right_frame.pack_propagate(False)
self.timer_score_label = tk.Label(right_frame, text="剩余时间00:00")
@ -204,11 +208,11 @@ class ExamApp:
for widget in self.root.winfo_children():
widget.destroy()
if __name__ == '__main__':
os.path.abspath(os.path.dirname(__file__))
root = tk.Tk()
app = ExamApp(root)
root.geometry("800x600")
root.resizable(False, False)
root.minsize(800, 600)
root.resizable(True, True)
root.mainloop()