我正在做的课程项目的一部分需要我创建一个登录页面并合并一个数据库,我已经成功地以正常形式使用python,但现在我不得不把它放到一个使用tkinter的图形用户界面中并使其工作我不得不在页面上使用一个函数来调用数据库中的记录,并与用户输入进行比较。我遇到的问题是,当我调用这个函数时,它什么都不做,可能是因为我的代码中有一个简单的错误,但是我不知道是出于某种原因还是出于某种原因。无法在课堂上获得功能
class LogInScreen(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
description = tk.Label(self, text="Please log in to gain access to the content of this computer science program.", font=LARGE_FONT)
description.pack()
label1 = tk.Label(self, text="Enter your username:")
label1.pack()
self.usernameEntry = tk.Entry(self)
self.usernameEntry.pack()
label2 = tk.Label(self, text="Enter your password:")
label2.pack()
self.passwordEntry = tk.Entry(self, show="*")
self.passwordEntry.pack()
notRecognised=tk.Label(self, text="")
logInButton = tk.Button(self, text="Log In", command=lambda: self.logUserIn)
logInButton.pack()
self.controller = controller
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(SplashScreen))
button1.pack()
button2 = tk.Button(self, text="Sign Up",
command=lambda: controller.show_frame(SignUpScreen))
button2.pack()
def logUserIn():
username = self.usernameEntry.get()
password = self.passwordEntry.get()
find_user = ("SELECT * FROM user WHERE username == ? AND password == ?")
cursor.execute(find_user,[(username),(password)])
results = cursor.fetchall()
if results:
controller.show_frame(HubScreen)
else:
loginResult = tk.Label(self, text="Account credentials not recognised, please try again")
loginResult.pack()
我不确知,我应该如何去获得此功能工作,真正需要帮助的人在这里都能够提供的。我花了很长时间看代码并且无所作为,我已经厌倦了解决它,执行程序的其他部分,但是如果没有这个功能,就很难评估它们。很抱歉,对于那些比我更有才华的人来说,这是一个不便之处,但这是一个学习过程,我正在努力改进。
通过'self':'def logUserIn(self):' –
你是怎么称呼它的? – mnistic
为什么你使用一个类登录屏幕? – mrCarnivore