I am trying to run a code that checks for Bluetooth connection if that particular connection is not there then the white screen will appear. for that, I am written Tkinter code and I am trying to control that white screen using multithreading but when I am killing the thread popup is not diapearing.
# Python program using
# traces to kill threads
import sys, threading, time
from tkinter import *
from tkinter import messagebox
class TraceThread(threading.Thread):
def __init__(self, *args, **keywords):
threading.Thread.__init__(self, *args, **keywords)
self.killed = False
def start(self):
self._run = self.run
self.run = self.settrace_and_run
threading.Thread.start(self)
def settrace_and_run(self):
sys.settrace(self.globaltrace)
self._run()
def globaltrace(self, frame, event, arg):
return self.localtrace if event == 'call' else None
def localtrace(self, frame, event, arg):
if self.killed and event == 'line':
raise SystemExit()
return self.localtrace
def func():
root=Tk()
l1=Label(root,text="please wait connection",width=200,font='Helvetica 22 bold').place(x=-1000,y=400)
root.overrideredirect(True)
root.overrideredirect(False)
root.attributes("-fullscreen", True)
root.mainloop()
t = TraceThread(target=func)
t.start()
time.sleep(2.5)
t.killed = True # sends a SIGTERM
t = TraceThread(target=func)
t.start()
time.sleep(2.5)
t.killed = True # sends a SIGTERM
if anyone got any way to kill it please share Thank you