@Aemyl is correct. Your problem is orphaned instances of Tk.
- First you instantiate Tk here:
self.window = ctk.CTk() - Then you do this in
submit:
self.window.withdraw() # hides the window self.window.quit() # exits the mainloop, but the instance is still live print(self.entrypassword.get()) # add this line and you can see that the widgets are still accessible - Then in
show_main_windowyou start another instance of Tk:window = ctk.CTk(). Remember, though, that the first instance is still there. - In
logout, you correctly kill the new instance:self.master.destroy. Again, first instance is still live. You just killed the second one. - Then you create a new instance of
LoginWindow, which starts another instance of Tk. But the old instance is still there, orphaned, because you never killed it. You just exited the mainloop.
Solution 1 - You actually want new instances
Easy fix. Just replace
self.window.withdraw() self.window.quit() with
self.window.destroy() # no more orphaned instance Solution 2 - You want to reuse the first instance
- Replace
self.window.withdraw() self.window.quit() with
self.window.withdraw() self.user_input.set('') # clear the Entry - Use
Toplevelinshow_main_window:
- Replace
window = ctk.CTk()withwindow = ctk.CTkToplevel() - Remove this line:
window.mainloop()
- In
logout, replace
login = LoginWindow() login.run() with
self.master.master.deiconify() - You'll need to handle closing the second window without invoking
logout, though, or you'll still have that hidden window hanging around if you close with the[X]button. Add this line just after creating the Toplevel window (inshow_main_window:
window.protocol('WM_DELETE_WINDOW', self.exit) I don't know how you're structuring your application, but either solution should fix the immediate issue.