Tkinter回调中的异常:布尔类型对象不可调用

时间:2019-05-27 12:16:30

标签: python tkinter

因此,当我在注册方面遇到错误时,我正在使用该Tkinter登录注册界面。最初我以为是因为类的实现不佳,但是不是。 这是我的代码:

def getinfo(event):
    register_window = Tk(screenName='RegisterWindow')
    register_hfont = Font(root=register_window, family='product sans', size=18)
    register_nfont = Font(root=register_window, family='product sans', size=10)
    head_label = Label(register_window, text='Welcome!')
    head_label.grid(row=0)
    head_label.configure(font=register_hfont)
    user_label = Label(register_window, text='Username ')
    user_label.grid(row=2)
    username_entry = Entry(register_window)
    username_entry.grid(row=2, column=2)
    user_label.configure(font=register_nfont)
    pass_label = Label(register_window, text='Password ')
    pass_label.grid(row=3)
    password_entry = Entry(register_window)
    password_entry.grid(row=3, column=2)
    pass_label.configure(font=register_nfont)
    email_label = Label(register_window, text='Email ')
    email_label.grid(row=4)
    email_entry = Entry(register_window)
    email_entry.grid(row=4, column=2)
    email_label.configure(font=register_nfont)
    name_label = Label(register_window, text='Name ')
    name_label.grid(row=5)
    name_entry = Entry(register_window)
    name_entry.grid(row=5, column=2)
    name_label.configure(font=register_nfont)

    print('data submissions successful')
    submit_button = Button(register_window, text='Register')
    submit_button.bind('<Button-1>', register(username_entry, password_entry, name_entry, email_entry))
    submit_button.grid(row=7, column=1)
    register_window.mainloop()
    if RegisterVar:
        register_window.destroy()
    else:
        pass


def register(eusername, epassword, ename, eemail):
    uid = eusername.get()
    pwd = epassword.get()
    name = ename.get()
    email = eemail.get()
    print('function called')
    register_command = 'insert into logininfo values("'+uid+'","'+pwd+'","'+name+'","'+email+'");'
    cursor.execute(register_command)
    RegisterVar = True
    print('Registration Successful!')
    return True

当我单击submit_button对象时,我遇到了此错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\adity\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
TypeError: 'bool' object is not callable

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您正在传递submit_button.bind调用结果 register,而不是函数本身(tinter将调用该函数)。