How do I update a button when attending an external event?

Asked

Viewed 40 times

0

I made a small application where it communicates with an external drive consulting some boolean variables. Depending on the status of these variables, a button is placed on the screen and a picture is included in this indicating the status of this unit. Ex.:

if Status_Botão_Aberto_A: 
    Photo_A = Photo_Aberto #carrega a figura referente ao status da unidade
Mais adiante: 
    A = Button(command=lambda : Comando(True, False, 1.Status_Botao_Aberto_A, Status_Botao_Fechado_A))
    A.place(x=76, y=87)m #posição do Botão
    A.config(imagem=Photo_A. width="42", height="42")
    A=Button(root)

My doubt is that to update these buttons, which are four, I have to communicate with each of the units to test the state variables. for that, I had to put before root.mainloop the command root.after(1000, Loop_interface), where every second calls the main function.

  • yes, and what problem are you having? .after is in fact the correct way to do this - your loop, instead of staying at a while, should run only once, checking the devices, and calling again the root.after(...)

  • Good afternoon and thank you for the clarification. I had not found any example of code similar to what I set out to do. My doubt was that using . after would not be forcing the code to execute inadvertently because there is the . mainloop method.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.