ProyectoFinalPython/app/widgets/abc/ThreadedTab.py

26 lines
693 B
Python

import threading
from abc import ABC, abstractmethod
from tkinter import Tk
from tkinter.ttk import Notebook
from tkinter import Frame
class ThreadedTab(ABC, Frame):
def __init__(self, root: Notebook | Tk, stop_event: threading.Event, **kwargs):
super().__init__(root, **kwargs)
self.stop_event = stop_event
self._thread = threading.Thread(target=self.__loop)
self.build()
self._thread.start()
def __loop(self):
while not self.stop_event.is_set():
self.task()
@abstractmethod
def build(self):
pass
@abstractmethod
def task(self, *args):
raise NotImplementedError("Method not implemented")