from tkinter import *
from tkinter import scrolledtext
class GuessGui:
def __init__(self, title):
self.root = Tk()
self.root.title(title)
self.root.geometry('800x600')
def build_menu(self):
root_menu = Menu(self.root)
# intializes a new sub menu in the root menu
file_menu = Menu(root_menu)
root_menu.add_cascade(label = "菜单", menu = file_menu)
file_menu.add_command(label = "显示记分板")
file_menu.add_command(label = "隐藏记分板")
file_menu.add_separator()
file_menu.add_command(label = "退出", command = self.root.quit)
self.root.config(menu = root_menu)
def build_timer(self, index):
self.timer = Label(self.root, text='00:00', font=('times', 20), fg='red')
self.timer.grid(row=index, column=0, columnspan=8)
def build_content(self, index):
group1 = LabelFrame(self.root, text='题目', padx=5, pady=5)
group1.grid(row=index, column=0, columnspan=8, padx=10, pady=10, sticky='ewns')
self.root.rowconfigure(index, weight=1)
self.root.columnconfigure(0, weight=1)
group1.rowconfigure(0, weight=1)
group1.columnconfigure(0, weight=1)
self.content = scrolledtext.ScrolledText(group1)
self.content.grid(row=0, column=0, sticky='ewns')
def build_buttons(self, index):
self.bu_tixing01 = Button(self.root, text='题型一', width=10)
self.bu_tixing01.grid(row=index,column=6, padx=10, pady=10, sticky='ew')
self.bu_answer = Button(self.root, text='显示答案', width=10)
self.bu_answer.grid(row=index,column=7, padx=10, pady=10, sticky='ew')
self.bu_tixing02 = Button(self.root, text='题型二', width=10)
self.bu_tixing02.grid(row=index+1,column=6, padx=10, pady=10, sticky='ew')
self.bu_assistance = Button(self.root, text='场外援助', width=10)
self.bu_assistance.grid(row=index+1,column=7, padx=10, pady=10, sticky='ew')
def build_gui(self):
index = 0
self.build_menu()
self.build_timer(index)
self.build_content(index+1)
self.build_buttons(index+2)
def main(self):
self.root.mainloop()
if __name__ == '__main__':
gui = GuessGui('竞猜游戏')
gui.build_gui()
gui.main()