Okay, so I'm just trying to get some clarification on why my code is not working like I thought it would.
I am building a GUI, and I want to display text on a Label
with a text variable. I have already made a function that updates the Label when the function is called, but of course that is not my problem.
My problem stems from me trying to implement a "print one letter at a time" type of label. While it prints to the terminal in the way I want it to, the label widget only updates after the whole function has finished (visually its the same as just printing the whole string instead of printing a letter at a time).
So what am I missing, what do I not understand? Can you guys help me? Let me post some code so you guys can see where my error is.
I tried both of these independently and they both game me the same result, which was not what I desired.
def feeder(phrase):
"""Takes a string and displays the content like video game dialog."""
message = ""
for letter in phrase:
time.sleep(.15)
message += letter
information.set(message)
#print message
def feeder2(phrase):
"""Same as feeder, but trying out recursion"""
current.index += 1
if current.index <= len(phrase):
information.set(phrase[:current.index])
time.sleep(.1)
feeder2(current.status())
I'm not positive if I need to post more code, so you guys can understand better, but if thats the case, I will do that.
Those 2 functions are used in this function
def get_info():
"""This function sets the textvariable information."""
#information.set(current)
feeder2(current.status())
Which in turn is used in this function
def validate():
""" This function checks our guess and keeps track of our statistics for us. This is the function run when we press the enter button. """
current.turn += 1
if entry.get() == current.name:
if entry.get() == "clearing":
print "Not quite, but lets try again."
current.guesses -= 1
if entry.get() != "clearing":
print "Great Guess!"
current.points += 1
else:
print "Not quite, but lets try again."
current.guesses -= 1
print current
get_info()
entry.delete(0, END)
current.name = "clearing"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…