0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried that, but can't really tell if it's working because it seems to have caused some other odd bugs. But that's probably just something else in my code gone wrong. :(
Are you able to describe these bugs? It might give some indication as to whether they're related to the dialog call; since tkMessageBox is essentially a very simple wrapper for the Windows MessageBox API call I'd say it's unlikely that it's a problem with the call itself.
Well, fixed the error I was having. But now there's a new (maybe simpler?) one: the messagebox just gets skipped, same as my original dialog.
OK, pressing enter submits the comment. Good to know. Anyway, I fixed it. Instead of storing the result of tkMessageBox(), I just used "if not tkmessageBox(): return", and that seems to work. Thanks!
0

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

1 Comment

Not IDLE, but I am running inside an experimental program with sort of a non-standard python interpreter in it. There could easily be something wacky in there. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.