I created a library management system with GUI and want to add a login GUI on it as well. What I want in the login window to pop up first and then, if the credentials are right, the management system opens up.
The problem I'm facing is that when I hit the login button, the management system opens but the login window also stays there. I have tried self.root.destroy()
before creating the window for management system but it closes all the windows and the management system also shuts down.`
What can I do?
class login_system():
def __init__(self, root):
self.root = root
self.root.title('Login')
self.root.geometry('500x250')
self.root.config(background='black')
self.loggedin = False
user = Label(root, text='Username:', font=('times new roman',20, 'bold'), fg='white', bg='black', padx=15,pady=10)
user.grid(row=0, column=0, padx=10, pady=10)
password = Label(root, text='Password:', font=('times new roman',20, 'bold'), fg='white', bg='black', padx=15 )
password.grid(row=1, column=0, padx=10, pady=10)
self.user_var= StringVar()
self.pass_var= StringVar()
user_ent = Entry(root, width=20, font=('times new roman',18, 'bold'),textvariable=self.user_var)
user_ent.grid(row=0, column=1)
pass_ent = Entry(root, width=20,font=('times new roman',18, 'bold'),textvariable=self.pass_var)
pass_ent.grid(row=1, column=1)
submit = Button(root, text='Login', command=self.login,font=('times new roman',18, 'bold'))
submit.grid(row=3, column=1, pady=10)
def login(self):
userinfo = self.user_var.get()
passinfo= self.pass_var.get()
conn = mysql.connector.connect(host='localhost', username='root', password = 'testpass', database = 'librarydb')
my_cursor = conn.cursor()
my_cursor.execute('SELECT username, password FROM login_system')
rows = my_cursor.fetchall()
conn.close()
for row in rows:
if row[0] ==userinfo:
if row[1]==passinfo:
tmsg.showinfo('Successful!', 'Logged In')
self.loggedin=True
self.newWindow= Toplevel(self.root)
self.app = LibraryManagementSystem(self.newWindow)
else:
tmsg.showinfo('Incorrect', 'Incorrect Password. Please try again')
break
else:
tmsg.showinfo('Incorrect', 'Incorrect username. Please try again')
break
class LibraryManagementSystem():
def __init__(self, root):
self.root= root
self.root.title('Library Management System')
self.root.geometry('1366x768')