Skip to main content
deleted 102 characters in body
Source Link
Sam
  • 143
  • 1
  • 11

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

  1. First you instantiate Tk here: self.window = ctk.CTk()
  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 = ctk.CTk(). Remember, though, that the first instance is still there.
  2. In logout, you correctly kill the new instance: self.master.destroy. Again, first instance is still live. You just killed the second one.
  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:
  • Replace window = ctk.CTk() with window = ctk.CTkToplevel()
  • Remove this line: window.mainloop()
  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) 

I don't know how you're structuring your application, but either solution should fix the immediate issue.

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

  1. First you instantiate Tk here: self.window = ctk.CTk()
  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 = ctk.CTk(). Remember, though, that the first instance is still there.
  2. In logout, you correctly kill the new instance: self.master.destroy. Again, first instance is still live. You just killed the second one.
  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:
  • Replace window = ctk.CTk() with window = ctk.CTkToplevel()
  • Remove this line: window.mainloop()
  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) 

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

  1. First you instantiate Tk here: self.window = ctk.CTk()
  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 = ctk.CTk(). Remember, though, that the first instance is still there.
  2. In logout, you correctly kill the new instance: self.master.destroy. Again, first instance is still live. You just killed the second one.
  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:
  • Replace window = ctk.CTk() with window = ctk.CTkToplevel()
  • Remove this line: window.mainloop()
  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) 

I don't know how you're structuring your application, but either solution should fix the immediate issue.

deleted 102 characters in body
Source Link
Sam
  • 143
  • 1
  • 11

@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 = tkctk.TkCTk()
  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 = tkctk.TkCTk(). Remember, though, that the first instance is still there.
  2. In logout, you correctly kill the new instance: self.master.destorydestroy. Again, first instance is still live. You just killed the second one.
  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:
  • Replace window = tkctk.TkCTk() with window = tkctk.ToplevelCTkToplevel()
  • Remove this line: window.mainloop()
  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) 

@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:
  • Replace window = tk.Tk() with window = tk.Toplevel()
  • Remove this line: window.mainloop()
  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) 

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

  1. First you instantiate Tk here: self.window = ctk.CTk()
  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 = ctk.CTk(). Remember, though, that the first instance is still there.
  2. In logout, you correctly kill the new instance: self.master.destroy. Again, first instance is still live. You just killed the second one.
  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:
  • Replace window = ctk.CTk() with window = ctk.CTkToplevel()
  • Remove this line: window.mainloop()
  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) 
Source Link
Sam
  • 143
  • 1
  • 11

@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:
  • Replace window = tk.Tk() with window = tk.Toplevel()
  • Remove this line: window.mainloop()
  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)