0
I’m willing to use the Sleep module team provides a load/wait effect on checking a condition. No use of Tkinter, the effect works perfectly, however, when I try to do the same with the Label of Tkinter, That doesn’t work anymore. Would anyone know why? follows an example code below:
from tkinter import *
from time import sleep
# Janela qualquer
janela = Tk()
# Variáveis com valores hipotéticos
a = 12
b = 15
lb_relacao_vh = Label(janela, font=("Century Gothic", 10, "bold"), bd=5,
text="Verificando a relação vão/altura.", anchor="w")
lb_relacao_vh.grid(row=0, column=0, sticky=W)
sleep(1)
lb_relacao_vh['text'] = "Verificando a relação vão/altura.."
sleep(1)
lb_relacao_vh['text'] = "Verificando a relação vão/altura..."
if a > b:
lb_relacao_vh['fg'] = 'red'
lb_relacao_vh['text'] = 'Verificando a relação vão/altura...ERRO!'
else:
lb_relacao_vh['fg'] = 'green'
lb_relacao_vh['text'] = 'Verificando a relação vão/altura...OK!'
janela.mainloop()
The
sleep()
generates a lock in the execution of the code, so that this does not occur you must execute thesleep()
asynchronously. In Python some options aremultiprocessing
,threading
orasyncio
. I had a similar problem when I needed to generate a chart (Example) who kept updating himself.– Renato Cruz
Hello @Renatocruz I don’t understand very well how I can apply this in my example (I’m learning on my own and so I don’t understand some things)
– Jhones Campos