好的,所以我只是想弄清楚爲什麼我的代碼不能像我想的那樣工作。Tkinter中的小部件如何更新?
我正在構建一個GUI,我想用文本變量在Label
上顯示文本。當函數被調用時,我已經創建了一個更新Label的函數,但這當然不是我的問題。
我的問題源於我試圖實現「一次打印一個字母」類型的標籤。當它以我想要的方式打印到終端時,標籤小部件僅在整個功能完成後才更新(在視覺上它與僅打印整個字符串相同,而不是一次打印一個字母)。
那麼我錯過了什麼,我不明白什麼?你們能幫我嗎?讓我發佈一些代碼,以便你們可以看到我的錯誤在哪裏。
我嘗試了這兩個獨立的,他們都玩我相同的結果,這不是我想要的。
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())
我還不能肯定,如果我需要發佈更多的代碼,所以你們可以更好地理解,但如果多數民衆贊成的情況下,我將這樣做。
這2個功能在此功能
def get_info():
"""This function sets the textvariable information."""
#information.set(current)
feeder2(current.status())
該消息又在這個函數
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"