So, I've got a small game application that uses Tkinter.
There's a static Label widget that contains graphics and which I can update in the normal way (usually with a function called update_image), a text input (Entry widget) that the player uses to input commands, and a textbox (Text widget) for output (with associated output function). There's a function called handlermain that grabs the input, and one called navigationmain that processes most of the commands after that.
What I need to be able to do is have a sequence moving through a few locations where I can cycle through a few images, printing associated text with each one, and with pauses rather than player input. I've tried two methods for this: putting sleep() calls into navigationmain (so trying to call the image updater and the text output, then wait a second before calling them again for the next round), and putting after() calls into update_image to put the wait in there. In both cases tkinter just cycles through all the delays and then dumps all the text at the end, skipping to the last image in the sequence.
I really can't see why this should be happening, though I may just be being dense - I assume there must be some built in buffering system that is stopping it updating until it's all done?
My most recent attempt, using root.after to try and make the delays happen, is below (this is a snippet out of the middle of the navigationmain() function, which is massively long so I won't give you the whole thing) - this does the same thing too, just spits it all out at the end. The "command" variable is usually given by player input: it's set to "PLACEHOLDER" by the calls here just so the function doesn't get confused, but it isn't really being used in these cases. Nb that app.update_image is also using app.location to find out which image to show.
elif app.location == 3: #Planet#
if command == "LOOK":
app.output ("You are on the planet PLANET. Your SHIP is here.")
else:
app.output ("Try saying something else!")
elif app.location == 38: #Travel to Planet#
app.update_image()
app.output ("Travel note 1")
app.location = 380
root.after(1000, navigationmain("PLACEHOLDER"))
elif app.location == 380:
app.update_image()
app.output ("Travel note 2")
app.location = 381
root.after(1000, navigationmain("PLACEHOLDER"))
elif app.location == 381:
app.update_image()
app.output ("Travel note 3")
app.location = 382
root.after(1000, navigationmain("PLACEHOLDER"))
elif app.location == 382:
app.update_image()
app.output ("Travel note 4 and final")
app.location = 3
root.after(1000, navigationmain("PLACEHOLDER"))
I expect that none of that made sense, but if any of it did then help would be much appreciated!