В приведенном ниже коде нажатие на BadButton никогда не отображает «Новый текст BadButton», оно ждет две секунды, а затем отображает «Третий текст BadButton». Как убедить скрипт отобразить оба сообщения.Использование Python 2.7.10
import os, sys
import time
import Tkinter
from Tkinter import *
def GoodButton():
global labeltext
time.sleep(2)
labeltext.set('New GoodButton text')
def BadButton():
global labeltext
labeltext.set('New BadButton text')
time.sleep(2)
labeltext.set('Third BadButton text')
# GUI construction
root = Tkinter.Tk()
root.title("Label Problem")
# set background
back = Tkinter.Frame(master=root, width=375, height=125, bg='white')
back.pack()
B1 = Tkinter.Button(root,text ="Test GoodButton", command = GoodButton)
B1.pack()
B1.place(height=25, width=100, x = 25, y = 25) # default x,y = 0,0
B2 = Tkinter.Button(root,text ="Test BadButton", command = BadButton)
B2.pack()
B2.place(height=25, width=100, x = 150, y = 25)
# add a label to show progress
labeltext = Tkinter.StringVar(value = 'Ready')
L1 = Tkinter.Label(root,textvariable = labeltext)
L1.pack()
L1.place(height=25, width=175, x = 150, y = 75)
# MAIN
root.mainloop()