如何在执行命令之前使tkinter按钮起作用

时间:2019-02-20 11:05:45

标签: python button tkinter

我尝试使按钮检查答案,但该按钮不起作用。

这是我的代码:

from tkinter import *
from tkinter import messagebox

question = '1+1=?'
key = '2'

def makeform(root, question):
   row = Frame(root)
   lab = Label(row, width=15, text=question, anchor='w')
   ent = Entry(row)
   row.pack(side=TOP, fill=X, padx=5, pady=5)
   lab.pack(side=LEFT)
   ent.pack(side=RIGHT, expand=YES, fill=X)
   entries = (question, ent)
   return entries

def check(entry, key):
    text = entry[1].get()
    if(text == key):
        messagebox.showinfo("Congratulation", "Great Job!")
    else:
        messagebox.showinfo("Uh Oh!", "Sorry, you're wrong.")

root = Tk()
ents = makeform(root, question)
b1 = Button(root,
            text='Finish',
            command= (lambda : check(ents, key), root.destroy))
b1.pack(side=LEFT, padx=5, pady=5)
root.mainloop()

它正确地弹出了窗口,但是当我单击按钮时,它什么也没做。

0 个答案:

没有答案