开发者

Calling a Python Tkinter wait_window inside a method and then resuming the method

I have a main window which creates a setup window (defined as a top level window) as a wait_window via this line of code:

 main.wait_window( Setup_Panel.setup_panel(main) )

That setup window has a method to writes its variables to a text file, however if the input file or output directory variables are blank I call a warning popup window as a wait_window of the setup window which is also defined as a top level window. The method is as follows:


def write_to_directory_file(main):
    main.execute_command = True
    if (main.input_directory_location.get().strip() == ""):
         main.wait_window( Error_Box.WarningPopup(main, "Input File Missing") )
    elif (main.output_directory_location.get().strip() == ""):
         main.wait_window( Error_Box.WarningPopup(main, "Output Directory Missing") )
    if execute_command:
         directory_file = open("plink.dir", 'w')
         directory_file.write("input_file: " + main.input_directory_location.get() + "\n")
         directory_file.write("output_directory: " + main.output_directory_location.get()    + "\n")
         directory_file.write("output_file: " + main.output_file_name.get() + "\n")
         directory_file.write("hom_name: " + main.HOM_name.get() + "\n")
         enable_parent_window(main.parent_main)
         main.destroy()
    print "FLAG"

The warning popup has the message given and two buttons one is Continue and the other is Cancel. If you press cancel the warning popup will be destroyed and set main.execute_command to False so the method won't continue. If you press continue it should destroy the popup and set main.execute_command to true so that the method will resume and write to the directory anyway. My problem is that when the warning popup is destroyed it doesn't return to the method immediately. Rather it won't return to that point and print "FLAG" until the setup window has also been destroyed.

How would I code it so that it would resume the method directly after the warning popup has been destroyed rather than after I destroy the warning window and the setup window? The only window that is calling .mainloop() is the main panel window.

The main panel is defined as: main = Tkinter.Tk() and calls main.mainloop()

The setup panel is defined as: setup_main = Tkinter.Toplevel()

The warning popup is defined as: warning_main = Tkinter.Toplevel()

Any help in figuring this out would be appreciated, 开发者_如何学Cthanks!


I have just encountered a problem just like the one you described. The child window appeared and worked but the function that called it hasn't resumed after the child window was closed. However after the parent window was closed too, the function that hasn't resumed in time finally resumed.

I found out, that I have accidentally set wrong parameter to the wait_window() line. I wrote the function name that created the child window instead of the child windows' own name.

Example:

#some code before
def create_cw(self):
    self.cw = Toplevel()
#some other after

What was wrong:

wait_window(self.create_cw)

What was the solution in my case:

wait_window(self.cw)

I found your question while I searched for solution to my problem. I hope I could help.


I found this old question because I had a similar problem.

According to my findings, wait_window(w) waits for w to be destroyed as in w.destroy(), then returns normal control flow to the program. In my case, I also implemented my own dialog window, but I didn't destroy the window. It may be your case.

TL/DR: The window argument to wait_window() must be destroyed for normal control flow to continue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜