如何使用螺纹在运行命令时阻止tkinter冻结
我正在使用TKINTER制作一个非常大的GUI,并且我有一个按钮来启动Ngrok服务器。它的工作方式是
def start_ngrok():
ngrok_creds = open("tools/ngrok_creds.txt", "r")
ngrok_creds_lines = ngrok_creds.readlines()
base_creds = ngrok_creds_lines[0]
ngrok_creds.close()
try:
os.system(f"ngrok.exe http --basic-auth {base_creds} file:///Mal_Files") # starts the ngrok server with custom credentials and opens a file to the webserver.
ngrok_started_q = True
except:
print("Error staring ngrok server, try again later.")
ngrok_started_q = False
os.kill
该按钮的简单代码。 (请记住所有这些功能都在课堂中,因此命令是主。start_ngrok)
run_ngrok = tkinter.Button(base_frame, text="Start Ngrok",command=Main.start_ngrok,width=20)
base_frame.create_window(80, 20, window=run_ngrok)
,但问题是当我单击按钮时,命令虽然gui冻结了并且无法正常工作。 Windows最终将其关闭,因为它不会响应。有人知道我如何简单地修复此问题或使用线程吗?
I'm making a pretty large scale GUI with tkinter, and I have a button to start a ngrok server. The way it works is simple
def start_ngrok():
ngrok_creds = open("tools/ngrok_creds.txt", "r")
ngrok_creds_lines = ngrok_creds.readlines()
base_creds = ngrok_creds_lines[0]
ngrok_creds.close()
try:
os.system(f"ngrok.exe http --basic-auth {base_creds} file:///Mal_Files") # starts the ngrok server with custom credentials and opens a file to the webserver.
ngrok_started_q = True
except:
print("Error staring ngrok server, try again later.")
ngrok_started_q = False
os.kill
code for the button. (keep in mind all these functions are in a class so the command is Main.start_ngrok)
run_ngrok = tkinter.Button(base_frame, text="Start Ngrok",command=Main.start_ngrok,width=20)
base_frame.create_window(80, 20, window=run_ngrok)
but the issue is when I click the button the command works though the GUI freezes and won't work. Windows eventually closes it because it won't respond. Anyone know how I could simply fix this or use threading?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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