从tkinter mainloop停止线程
使用按钮i m在单独的线程上执行脚本,完成后,该线程需要返回到我启动的屏幕。 如果我在脚本的末尾提到该片段,因为我试图从另一个线程调用TKINTER线程,这会给我带来TCL错误。
我想知道如何实现这一目标。
我已经尝试了这两种方式。
第一:
#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#
我尝试使用WALE循环以继续检查线程的状态如果该线程还活着,请继续使用主循环循环,如果不返回Screen1。没有用。
我还有什么选项?我需要暂时解决此问题,因为我只学习它,但我必须提出它。我计划将其转移到另一个GUI,这是最佳临时修复方法的方法? 我不想再次编写整个代码,因为它是多个屏幕。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论