0

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()
BoBBob123
  • 25
  • 7
  • Briefly: `withdraw()` it. When you want to see it again, use `deiconify()`. – TigerhawkT3 Jan 17 '16 at 22:22
  • ok thanks but that only answers half of my question how then can i associate the window wwith another .py file and build from scratch – BoBBob123 Jan 17 '16 at 22:27
  • I don't see anything in your question or the accompanying code about having your program start another program. I also don't know what you mean by associating a source file with a window. If you want to access classes and functions in another source file, `import` it. If you want to run additional scripts (which you almost certainly don't need for a simple Tkinter app), you could use the `os` or `threading` modules. If you have a new question, ask a new question. – TigerhawkT3 Jan 17 '16 at 22:34
  • The deiconfify isnt what im looking for that is just hiding it, I want it so when i login a new window appears and the Login Screen is completed gone non-existent – BoBBob123 Jan 18 '16 at 17:32

0 Answers0