0

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()
enno4859
  • 51
  • 1
  • 9

4 Answers4

4

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.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • I start the application with making my window class and from there I make an object Duplicates or to be more precise I have it as None in __init__ but it is created when the button new file is pressed. I create an instance of popwindow within Duplicates so I do not understand why that would interupt the main window. I since tried to have popWindow as a method within window and it still shuts down as soon as I destroy the popwindow. Must be I do not understand either tkinter, python threading or both. – enno4859 Sep 29 '14 at 07:24
  • @enno4859: are you using threads? Are you calling mainloop more than once? Those would be important details that you left out of your question. – Bryan Oakley Sep 29 '14 at 10:37
  • yes a second mainloop for the top window so it would wait for input from user. – enno4859 Oct 01 '14 at 12:05
  • 1
    @enno4859: You don't want to do that. You should call the `wait_window` method on the toplevel. That will enter a new event loop and then exit as soon as the window is destroyed. – Bryan Oakley Oct 01 '14 at 12:52
0

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.

W1ll1amvl
  • 1,219
  • 2
  • 16
  • 30
0

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()

enno4859
  • 51
  • 1
  • 9
  • What you say doesn't make a lot of sense. You are correct that `destroy()` won't stop the mainloop. You don't ever want to stop the mainloop until your program exits. Are you running more than one mainloop? Perhaps that is the real root of your problem. – Bryan Oakley Sep 29 '14 at 10:35
  • yes a top.mainloop for the toplevel window. If I do not have a mainloop for it it will not wait for an input from the user. – enno4859 Oct 01 '14 at 12:04
0

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()

Guydangerous99
  • 147
  • 1
  • 12