简体   繁体   中英

How to pause Python while Tkinter window is open?

I'm writing a program that sometimes encounters an error. When it does, it pops up a Tkinter dialog asking the user whether to continue. It's a more complicated version of this:

keep_going = False
KeepGoingPrompt(keep_going)
if not keep_going:
    return

The prompt sets keep_going to True or leaves it False . Problem is, the code seems to continue while KeepGoingPrompt is open. I tried storing a reference to the prompt and adding a loop like

while prompt:
    time.sleep(1)

but python gets stuck in the loop and freezes. Is there a better way to do it?

Thanks

You can use the tkMessageBox class to pop up a question dialog that is modal and won't return until the user clicks a button. See the Tkinter book for details.

1) Are you running your code inside IDLE? It might be responsible for making the dialogue non-blocking while it really should be blocking.

2) If running outside IDLE does not help, look for tkinter/dialogue options which specify whether behavior is blocking or non-blocking

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM