You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import tkinter as tk
|
|
|
|
from tkinter import messagebox
|
|
|
|
|
|
|
|
# 单词列表
|
|
|
|
words = ["apple", "banana", "cherry", "date", "elderberry"]
|
|
|
|
|
|
|
|
class WordApp(tk.Tk):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.title("单词学习")
|
|
|
|
self.current_word_index = 0
|
|
|
|
self.word_label = tk.Label(self, text="", font=("Helvetica", 20))
|
|
|
|
self.word_label.pack(pady=20)
|
|
|
|
self.create_buttons()
|
|
|
|
|
|
|
|
def create_buttons(self):
|
|
|
|
self.know_button = tk.Button(self, text="认识", command=self.show_next_word, width=10)
|
|
|
|
self.not_know_button = tk.Button(self, text="不认识", command=self.show_next_word, width=10)
|
|
|
|
self.know_button.pack(side=tk.LEFT, padx=10, pady=10)
|
|
|
|
self.not_know_button.pack(side=tk.RIGHT, padx=10, pady=10)
|
|
|
|
|
|
|
|
def show_next_word(self):
|
|
|
|
if self.current_word_index < len(words):
|
|
|
|
self.word_label.config(text=words[self.current_word_index])
|
|
|
|
self.current_word_index += 1
|
|
|
|
else:
|
|
|
|
messagebox.showinfo("结束", "所有单词已学习完毕!")
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app = WordApp()
|
|
|
|
app.mainloop()
|