如何在没有tkinter gui冻结的情况下执行命令

发布于 2025-02-13 07:30:02 字数 908 浏览 2 评论 0原文

我一直在研究GUI,我需要执行的一个命令是ngrok.exe。但是,每当我使用os.System(f“ ngrok.exe http -basic-auth {base_creds} file://// mal_files”)它会冻结GUI和不继续工作。有什么方法可以解决此问题吗?我听说线​​程可能会有所帮助,但我对它们一无所知。

代码

    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")  
          ngrok_started_q = True
        except:
          print("Error staring ngrok server, try again later.")
          ngrok_started_q = False
          os.kill
    
# Button to start ngrok code
run_ngrok = tkinter.Button(base_frame, text="Start Ngrok",command=Main.start_ngrok, width=20)
base_frame.create_window(80, 20, window=run_ngrok)

I've been working on a GUI, and one command I need to execute is ngrok.exe. But whenever I use os.system(f"ngrok.exe http --basic-auth {base_creds} file:///Mal_Files") it freezes the GUI and wont continue working. Is there any way to fix this? I've heard threads could help but i dont know anything about them.

CODE

    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")  
          ngrok_started_q = True
        except:
          print("Error staring ngrok server, try again later.")
          ngrok_started_q = False
          os.kill
    
# Button to start ngrok code
run_ngrok = tkinter.Button(base_frame, text="Start Ngrok",command=Main.start_ngrok, width=20)
base_frame.create_window(80, 20, window=run_ngrok)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文