我试图做一个简单的数学运算,当你给出正确答案时它会说“正确”,而当你做错时它会说“错误”;但是,它给出了一个错误:
Tkinter 回调 Traceback 中的异常(最近一次调用最后一次):文件“C:\Users\yu.000\AppData\Local\Programs\Python\Python38-32\lib\tkinter_init _.py ”,第 1883 行,调用 返回self.func(*args) TypeError: check() 缺少 1 个必需的位置参数:'entry'
这是代码:
import tkinter as tk
import tkinter.messagebox as tkm
window = tk.Tk()
window.title('my tk')
window.geometry('550x450')
def math1():
e = tk.Tk()
e.geometry('200x150')
tk.Label(e, text = '10', height = 2).pack()
tk.Label(e, text = '+ 12', height = 2).place(x=80, y=25)
er = tk.StringVar()
def check(entry):
if entry == 22:
tkm.showinfo('correct', 'correct!')
else:
tkm.showerror('try again', 'wrong, try again')
entry = tk.Entry(e, textvariable = er)
entry.place(x=90,y=60)
tk.Button(e, text = 'submit', command = check).place(x=80, y = 80)
tk.Button(window, text='1', command = math1).pack()
window.mainloop()