Skip to content

Instantly share code, notes, and snippets.

@nenodias
Created April 24, 2024 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nenodias/e3c310be0bfec98754fea99e6c253820 to your computer and use it in GitHub Desktop.
Save nenodias/e3c310be0bfec98754fea99e6c253820 to your computer and use it in GitHub Desktop.
Exemplo tkinter utilizando thread
from threading import Thread
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)
botao = Button(janela, text="Iniciar", command=lambda: Thread(target=clicou).start())
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