Skip to content

Instantly share code, notes, and snippets.

@nenodias
Last active April 24, 2024 03:00
Show Gist options
  • Save nenodias/abf42465ff3650650b9aaa05e46fc6c5 to your computer and use it in GitHub Desktop.
Save nenodias/abf42465ff3650650b9aaa05e46fc6c5 to your computer and use it in GitHub Desktop.
Exemplo tkinter utilizando o método after (Callback)
from tkinter import *
from time import sleep
cont=0
def clicou():
global cont
while True:
cont+=1
conta_label.config(text=f"contando: {cont}")
print(cont)
sleep(1)
if cont <= 10:
break
janela = Tk()
janela.geometry("200x100")
conta_label = Label(janela, text="contando: 0")
conta_label.grid(row=8, column=0, padx=8, pady=15)
fn_clicou = lambda : janela.after(100, lambda: clicou())
botao = Button(janela, text="Iniciar", command=fn_clicou)
botao.grid(column=0, row=10, padx=15, pady=15)
janela.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment