79639341

Date: 2025-05-26 17:14:07
Score: 1
Natty:
Report link

@Aemyl is correct. Your problem is orphaned instances of Tk.

EDIT: I'm just using tk.Tk() here but the solution should be the same. Just use the ctk equivalents.

  1. First you instantiate Tk here: self.window = tk.Tk()
  2. 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
  1. Then in show_main_window you start another instance of Tk: window = tk.Tk()
  2. In logout, you correctly kill the new instance: self.master.destory
  3. 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

  1. Replace
self.window.withdraw()
self.window.quit()

with

self.window.withdraw()
self.user_input.set('')  # clear the Entry
  1. Use Toplevel in show_main_window:
  1. In logout, replace
login = LoginWindow()
login.run()

with

self.master.master.deiconify()
  1. 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 (in show_main_window:
window.protocol('WM_DELETE_WINDOW', self.exit)
Reasons:
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Aemyl
  • Low reputation (0.5):
Posted by: Sam