我目前正在一个学校项目中,我必须开发一个数据库系统。我的登录屏幕运行正常。当用户登录时,将打开主菜单屏幕,但是,在理想情况下,如果希望关闭它,登录屏幕将保持打开状态。我的代码附在下面并附有屏幕图像。
class Toplevel1:
def UserLogin(self): #Login function for staff members
while True:
staffid = self.Entry1.get();
password = self.Entry2.get();
with sqlite3.connect("LeeOpt.db") as db: #Connects to the database file
cursor = db.cursor()
find_user = ('SELECT * FROM Login WHERE StaffID = ? AND Password = ?')
cursor.execute(find_user, [(staffid),(password)])
results = cursor.fetchall()
if results:
for i in results:
MainMenu.create_Toplevel1(root)
return("exit")
else:
tkinter.messagebox.showerror("Error", "The staffID or password is incorrect, please try again.")
time.sleep(1)
return("exit")
答案 0 :(得分:1)
在tkinter窗口的登录屏幕上使用.destroy方法,一旦登录即可销毁它(打开主菜单窗口后立即执行此操作)。 Link to destroy method on tutorials point