Python:为什么tkinter不执行一个过程,尽管它在按钮中被调用?
代码: 我正在尝试编写一个程序,允许您创建抽认卡集。在研究抽认卡时,tkinter程序会打包一个按钮,用户可以点击该按钮从术语切换到其定义。当用户再次单击按钮时,程序将切换到列表中的下一个术语。Python:为什么tkinter不执行一个过程,尽管它在按钮中被调用?,python,tkinter,Python,Tkinter,代码: 我正在尝试编写一个程序,允许您创建抽认卡集。在研究抽认卡时,tkinter程序会打包一个按钮,用户可以点击该按钮从术语切换到其定义。当用户再次单击按钮时,程序将切换到列表中的下一个术语。 在replaceflashcard()函数中的计数增加之前,程序将按其应该的方式运行。它不执行我在中编写的studyset()函数。我反复单击flashcard按钮,但它仍然显示定义。这是因为您对函数和按钮使用了相同的名称studyset。该按钮覆盖该功能。为按钮使用另一个名称。@acw1668 OHH
在replaceflashcard()函数中的计数增加之前,程序将按其应该的方式运行。它不执行我在中编写的studyset()函数。我反复单击flashcard按钮,但它仍然显示定义。这是因为您对函数和按钮使用了相同的名称
studyset
。该按钮覆盖该功能。为按钮使用另一个名称。@acw1668 OHHHHH tysm man。
import tkinter as tk
main = tk.Tk()
main.wm_title("Flashcards")
terms = []
defs = []
count = 0
configuration = tk.Frame(bg = "sky blue")
configuration.grid(row = 0, column = 0)
flashcards = tk.Frame(bg = "sky blue")
flashcards.grid(row = 0, column = 0)
flashcard = tk.Button(flashcards, font = ("Dotum", 12))
finish = tk.Label(flashcards, font = ("Dotum", 24), border = 10)
def createflashcard():
terms.append(ent_term.get())
defs.append(ent_def.get())
ent_term.delete(0, "end")
ent_def.delete(0,"end")
def studyset():
global count
global finish
global flashcard
if count == 0:
finish.pack_forget()
flashcards.tkraise()
flashcard.pack(side = "top")
configuration.grid_forget()
flashcard.configure(text = terms[count], command = replaceflashcard)
print(terms)
def replaceflashcard():
global count
global flashcard
global finish
flashcard.configure(text = defs[count])
if count == (len(terms) - 1):
finish.pack(side = "top")
finish.configure(text = "End of Set!")
flashcard.configure(command = endset)
else:
count = count + 1
flashcard.configure(command = studyset)
def endset():
global count
global finish
global flashcard
flashcard.configure(text = "Restart set", command = studyset)
count = 0
ent_term = tk.Entry(configuration, text = "Enter your term", font = ("Dotum", 12))
ent_term.pack(side = "top")
ent_def = tk.Entry(configuration, text = "Enter definition", font = ("Dotum", 12))
ent_def.pack(side = "top")
create = tk.Button(configuration, text = "Create
flashcard", font = ("Dotum", 12), command = createflashcard)
create.pack(side = "top")
studyset = tk.Button(configuration, text = "Study set", font = ("Dotum", 12), command = studyset)
studyset.pack(side = "top")
main.mainloop()