Created
April 24, 2024 03:00
-
-
Save nenodias/e3c310be0bfec98754fea99e6c253820 to your computer and use it in GitHub Desktop.
Exemplo tkinter utilizando thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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