I'm currently creating a login page for my application and all I am wanting to do is when I've successfully logged in the window changes from login to a new blank window from which I can attach to a class and begin using as my projectMain I've tried multiple ways all have which proved unsuccessful. The current stage of my code I have the window displaying but in addition I cant close the login as it closes whole program, I've worked out that it is because it is the master class but how can I bypass this, feel free to change or post ways on improving my code as I am still a rough beginner in python
import tkinter
from tkinter import *
from tkinter import messagebox
class LoginFrame(Frame):
counter = 0
def __init__(self, master):
Frame.__init__(self, master)
self.label_1 = Label(self, text="Username")
self.label_2 = Label(self, text="Password")
self.entry_1 = Entry(self)
self.entry_2 = Entry(self, show="*")
self.label_1.grid(row=0)
self.entry_1.grid(row=0, column=1)
self.label_2.grid(row=1)
self.entry_2.grid(row=1, column=1)
self.checkbox = Checkbutton(self, text="Keep me logged in")
self.checkbox.grid(columnspan=2)
self.logbtn = Button(self, text="Login", command=self.login_btn)
self.logbtn.grid(columnspan=2)
self.pack()
def login_btn(self):
#print("On click action/event")
Username = self.entry_1.get()
Password = self.entry_2.get()
#print(username, password)
if Username == "Lewis" and Password == "starwars10":
messagebox.showinfo("Login Successful", "Welcome Lewis")
self.counter += 1
t = tkinter.Toplevel(self)
t.wm_title("Window #%s" % self.counter)
l = tkinter.Label(t, text="This is window #%s" % self.counter)
l.pack(side="top", fill="both", expand=True, padx=100, pady=100)
#TODO fix quit so that as one window opens old one closes
#self.quit() # destroys login window
else:
messagebox.showerror("Login Incorrect", "Invalid Credentials")
root = Tk()
root.geometry("300x200")
lf = LoginFrame(root)
root.mainloop()