单词本
from tkinter import *
from tkinter import scrolledtext
WIN_W, WIN_H = (600, 480)
class Game:
def __init__(self, root: Tk):
self.root = root
root.geometry('%dx%d+50+50' % (WIN_W, WIN_H))
root.title("单词本")
frame = Frame(root, width=WIN_W, height=int(WIN_H * 0.8))
frame.pack(side=TOP)
lf = LabelFrame(root, text='操作记录', width=WIN_W)
lf.pack(side=BOTTOM)
self.logText = scrolledtext.ScrolledText(lf, bg='LightCyan', width=WIN_W, state=DISABLED)
self.logText.pack()
menu_word = Menu(root, tearoff=0)
menu_word.add_command(label="单词列表", command=self.word_list_view)
menu_word.add_separator()
menu_word.add_command(label="添加单词", command=self.word_add_view)
menu_root = Menu(root)
menu_root.add_cascade(label="单词", menu=menu_word)
menu_root.add_command(label="测试", command=self.word_test_view) # 原理:先在主菜单中添加一个菜单,与之前创建的菜单进行绑定。
menu_root.add_command(label="雷达图", command=self.word_radar)
menu_root.add_command(label="退出", command=root.quit)
root.config(menu=menu_root)
def log(self, s: str):
print(s)
self.logText.config(state=NORMAL)
self.logText.insert(END, s + "\n")
self.logText.see(END)
self.logText.config(state=DISABLED)
def start(self):
self.root.mainloop()
def word_add_view(self):
self.log("添加单词")
def word_list_view(self):
self.log("单词列表")
def word_test_view(self):
self.log("单词测试")
def word_radar(self):
self.log("雷达图")
if __name__ == '__main__':
game = Game(Tk())
game.start()