22 lines
563 B
Python
22 lines
563 B
Python
import threading
|
|
from abc import ABC, abstractmethod
|
|
from threading import Thread
|
|
from tkinter import Label
|
|
|
|
|
|
class ThreadedLabel(ABC, Label):
|
|
|
|
def __init__(self, root: Label, stop_event: threading.Event, **kwargs):
|
|
super().__init__(root, **kwargs)
|
|
self.stop_event = stop_event
|
|
self.declared_thread: Thread = threading.Thread(target=self.__loop)
|
|
|
|
self.declared_thread.start()
|
|
|
|
def __loop(self):
|
|
while not self.stop_event.is_set():
|
|
self.task()
|
|
|
|
@abstractmethod
|
|
def task(self, *args):
|
|
pass |