2.stop_thread()
DescriptionΒΆ
Stop the thread running on UNIHIKER
SyntaxΒΆ
GUI.stop_thread(Thread object)
ParametersΒΆ
** Thread object
ReturnΒΆ
**None
Example DescriptionΒΆ
In this simple example, our main goal is to stop the thread running on UNIHIKER.
Hardware RequiredΒΆ
Example CodeΒΆ
Instantiate an object of the GUI class within the UNIHIKER class. Define two callback functions for display purposes. The first callback function initiates a clock thread using the start_thread() function and maintains its operation through a delay loop. After 6 seconds, the thread is closed using the stop_thread() function. Note: Thread functions do not loop by default.
import time
from unihiker import GUI # Import Package
gui=GUI() # Instantiating GUI classes
clock = gui.draw_clock(x=120, y=160, r=100, h=3, m=4, s=5, color=(255, 0, 0), onclick=lambda: print("clock clicked"))
def clock_update():
while True:
t = time.localtime()
clock.config(h=time.strftime("%H", t), m=time.strftime("%M", t), s=time.strftime("%S", t))
time.sleep(0.5)
# Multithreaded startup
clock_thread = gui.start_thread(clock_update)
time.sleep(6)
# Stop Thread
gui.stop_thread(clock_thread)
while True:
time.sleep(0.1)
