Parallax Sugar
Parallax Sugar

Reputation: 705

Why are tkinter windows/boxes closing erratically and stopping the program?

To cut a long story short, I've been doing an interactive GUI (tkinter) word-game program for school. At first, everything went smoothly, but having finished the code, it has started to behave in unexpected ways when I run it. Some dialog boxes (particularly the

 if tkinter.messagebox.askyesno():

thingy) just rapidly answer themselves with the 'no' option, rather than waiting for user input. Sometimes, the windows close off completely and cause the whole program to quit. However, although these errors are all the same (i.e. tkinter windows closing/answering themselves/stopping the program before they should), they usually happen in different places every time. I'm not sure if that's to do with the fact that tkinter is nested, opened, re-opened and closed numerous times within other code, which is making it run messily, but I have only destroyed tkinter windows in the right places, as far as I know.

Part of my code involves a while loop - I'm not sure if that could be interfering with the mainloop()s, but I couldn't find another way to allow the user to repeat the game as many times as they want.

I know this question is vague, but I'm mainly looking for tips - if it would be easier to diagnose if I split it up into different sections and tidy it up a bit, found an alternative for the while loop, etc.

Thanks!

Upvotes: 0

Views: 114

Answers (1)

Alan
Alan

Reputation: 3042

TKinter dialogs should be fully completed and the results stored before moving onto the next section of code.

Make sure you provide all the arguments to the dialog (your example doesn't include the parameters).

result = tkinter.messagebox.askyesno('Confirm', 'Do you want to do this')
if result == true:

Upvotes: 1

Related Questions