Using the button I m executing a script on a separate thread, which after completing needs to come back to the screen where I started from. If I mention that snippet at the end of my script which I m running on a separate thread giving me a TCL error since I m trying to call the Tkinter thread from another thread.
I want to know how to achieve this goal.
I have tried these 2 way..
1st:
#imports
#from the screen1 button I m sending arg to this function to run on seperate thread.
def screen2(arg):
#this window show the status of script progress bar, label status etc#
window.geometry("1215x770")
window.configure(bg="#FFFFFF")
#background canvas#
#progressbar#
#label#
def task():
if arg = foo:
#I cant use join here or else it will wait for the script to complete without showing screen2#
#I tried putting the mainloop after starting the thread, but as it means the tkinter is on hault it wont execute the after command.
t1 = threading.Thread(target=script, args(ag1, ag2,)).start()
window.mainloop()
window.resize(false, false)
response = messagebox.showinfo("Task", "Script Ran!")
if response:
screen1()
else:
t1 = threading.Thread(target=script, args(ag3, ag4,)).start()
window.mainloop()
window.resize(false, false)
response = messagebox.showinfo("Task", "Script Ran!")
if response:
screen1()
task()
def script(arg1, arg2):
#Doing something here#
I tried using the while loop to keep checking the status of the thread if it's alive then keep looping with the main loop in it if not go back to screen1. which didn't work.
What else option do I have? I need to fix this temporarily since I m only learning it but I have to present it. I m planning to shift it to another GUI whats the best temporary fix for this? I don't want to write the whole code again because it's multiple screens.
mainloop()
runs loop which blocks rest of code. If you want to check thread then you couldwindow.after(milliseconds, function)
to run code periodically and check if thread is still alive. But you have to assign thread to global variable to access it in another function. – furasscrreen1()
inscreen2()
can create recursion. Maybe it could be better to exitscreen2
to go back toscreen1
- eventuallyscreen2
couldreturn response
and runif
ousidescreen2
– furas"temporary fix"
is the worst. Your code may need many changes. There should be function which runsscreen2
and get result from this function and later it decide if it has to runscreen1
- some kind ofscreens manager
– furas