Reputation: 51
I have a class Duplicates
that checks for duplicates within 40 words.
I have a class Window
that creates and runs the main window where i post the result.
I have a class popWindow
that creates a Toplevel window when asking user for what to do with a possible double.
My problem is closing the popWindow
once a choice is submited.
the version I have that actualy runs and posts an aswer (the text with marked duplicates) uses quit to terminate the window (meaning the popup is still there in the way) or to simply have multiple popups till you are done.
class Duplicates:
def markWord(self):
self.appendMarkedWord(self.word)
self.checked.append(self.word)
self.pop.topLevel_exit()
return ""
class popUpWindow:
temp = Button( self, font = 8,
text = "Allowed this run only",
command = app.newFile.markWord
)
temp.place( x = 178,
y = 55
)
if I instead use .destroy()
the window shuts but the program stops running and that is worse.
How do i work around this so it shuts the window but still continues to run the program?
Ok, after many many hours it seemed the real problem was destroy() was not stopping my popUpWindow.mainloop() so I now have altered my exit code to first do quit() and then do destroy(). This is not what i have seen as examples at all and it seems to me that destroy() on toplevel mainloop is not terminating it (destroy() works fine on my root.mainloop).
def topLevel_exit(self):
self.pop.quit()
self.pop.destroy()
Upvotes: 0
Views: 8122
Reputation: 145
If you use a topLevel window, self.pop.destroy()
should still work as you are using mainloop()
Otherwise use quit()
or both but in my opinion of all of these, I prefer destroy()
Upvotes: 0
Reputation: 51
The solution for me was:
def topLevel_exit(self):
self.top.quit()
self.top.destroy()
I do not know if this is common praxis but is what I had to do since destroy was not stoping my top.mainloop()
Upvotes: 0
Reputation: 1269
A way to hide the window and keep the program running would be to use .withdraw()
on the window, and .reiconify()
to get it back (if needed). Or you could use .destroy()
on a Toplevel
window. If you need examples just ask, hope this helps you.
Upvotes: 0
Reputation: 386010
If you call destroy()
on a toplevel window, it will not stop the application from running. If your application stops, there must be more to your code that what you're telling us. Without question, the right way to get rid of the popup is to call destroy
on the instance of the Toplevel
.
Upvotes: 4