【发布时间】:2017-05-07 13:01:49
【问题描述】:
这是我得到的错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Denis\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\Denis\Desktop\Python\Sunday Work.py", line 47, in <lambda>
RegistrationButton = Button(userRegister,text="Register",font=("monaco", 10),width=30,relief="groove",command=lambda: accountRegister(RegistrationUsernameEntry.get(),RegistrationPasswordEntry.get())).place(x=26,y=230)
AttributeError: 'NoneType' object has no attribute 'get'
我正在创建一个用户帐户登录和注册系统 - 在上面的代码中我创建了一个函数,并在其中创建了一个顶层以在单击登录屏幕上的注册按钮时打开一个新窗口。我设置了与 sql 的连接并创建了一个游标等,但是每次我在我所做的条目中插入一些东西并单击“注册”时,我都会收到此错误。有什么想法可能是错的吗?
这是它的一些代码
def userRegister():
userRegister = Toplevel(root, bg="#a1dbcd")
userRegisterTitle = userRegister.title("Registration")
userRegister.geometry("300x300")
userRegister.resizable(width=False, height=False)
#Creates userRegister window content to register
RegistrationForm = Label(userRegister,text="REGISTRATION FORM",bg="#a1dbcd",font=("monaco", 20)).pack()
RegistrationFormDesign = Label(userRegister,bg="black",width=50).pack()
RegistrationFormInfo = Label(userRegister,text="To create an account fill in the form . . ",bg="#a1dbcd",font=("monaco", 9)).pack()
RegistrationUsername = Label(userRegister,text="Username:",bg="#a1dbcd",font=("monaco", 12)).place(x=10,y=100)
RegistrationUsernameEntry = Entry(userRegister,fg="black",relief="groove",width=20,font=("monaco", 10),highlightthickness=1,highlightbackground="black").place(x=10,y=130)
RegistrationPassword = Label(userRegister,text="Password:",bg="#a1dbcd",font=("monaco", 12)).place(x=10,y=160)
RegistrationPasswordEntry = Entry(userRegister,fg="black",relief="groove",show='*',width=20,font=("monaco", 10),highlightthickness=1,highlightbackground="black").place(x=10,y=190)
*RegistrationButton = Button(userRegister,text="Register",font=("monaco", 10),width=30,relief="groove",command=lambda: accountRegister(RegistrationUsernameEntry.get(),RegistrationPasswordEntry.get())).place(x=26,y=230)*
CloseButton = Button(userRegister,text="Close",font=("monaco", 10),width=30,relief="groove",command=userRegister.destroy).place(x=26,y=265)
#Stores data inputted within entries as well as displaying a message when done
def accountRegister(UsernameRegister,PasswordRegister):
print(UsernameRegister,PasswordRegister)
cursor.execute('''INSERT INTO users(username, password)VALUES(?, ?)''',(UsernameRegister, PasswordRegister))
messagebox.showinfo("Account Registration Info", " Account is now registered! ")
【问题讨论】:
-
我通过在每个下放置 .pack 或 .place 来修复它。例如[这里的代码] [名称].pack
标签: python python-3.x tkinter sqlite