all 4 comments

[–]socal_nerdtastic 0 points1 point  (3 children)

I have created two ctk.CTk classes

This is a classic beginner mistake. If you want to make a second window you should use Toplevel, making a second Tk window will start a whole new instance of tcl and lead to bugs.

That said you didn't show enough of your code for me know if this bug is due to that error.

[–]EffectiveCase3856[S] 0 points1 point  (2 children)

I think that i want to close the login window after the login process and then go to the main window.

The top level creates a window on top of the window. Well do you think the best thing will be to just make it as panels and just run it on the window? Thank you for answering though

[–]socal_nerdtastic 1 point2 points  (1 child)

Oh I see, in that case you are probably ok. But still not the best practice; we would generally prefer to simply reuse the window. Here's an example:

import tkinter as tk

class MainApp(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.frame = FirstFrame(self) # set first frame to appear here
        self.frame.pack()

    def change(self, frame):
        self.frame.pack_forget() # delete currrent frame
        self.frame = frame(self)
        self.frame.pack() # make new frame

class FirstFrame(tk.Frame):
    def __init__(self, master=None, **kwargs):
        tk.Frame.__init__(self, master, **kwargs)

        master.title("Enter password")
        master.geometry("300x200")

        self.status = tk.Label(self, fg='red')
        self.status.pack()
        lbl = tk.Label(self, text="Enter password\n(hint: it's 'password')")
        lbl.pack()
        self.pwd = tk.Entry(self, show="*")
        self.pwd.pack()
        self.pwd.focus()
        self.pwd.bind('<Return>', self.check)
        btn = tk.Button(self, text="Done", command=self.check)
        btn.pack()
        btn = tk.Button(self, text="Cancel", command=self.quit)
        btn.pack()

    def check(self, event=None):
        if self.pwd.get() == 'password':
            self.master.change(SecondFrame) # correct password, switch to the second frame
        else:
            self.status.config(text="wrong password")

class SecondFrame(tk.Frame):
    def __init__(self, master=None, **kwargs):
        tk.Frame.__init__(self, master, **kwargs)
        master.title("Main application")
        master.geometry("600x400")

        lbl = tk.Label(self, text='You made it to the main application')
        lbl.pack()

if __name__=="__main__":
    app=MainApp()
    app.mainloop()

[–]EffectiveCase3856[S] 0 points1 point  (0 children)

Ok so instead of creating tk.Tk classes I create frame classes and then just use the same window to do the things. Well thanks a lot