gpt4 book ai didi

python - 在 python GTK3 中单击按钮后窗口卡住

转载 作者:行者123 更新时间:2023-11-28 23:01:19 25 4
gpt4 key购买 nike

你好,我有一些命令,平均运行 30 分钟,当我单击由 GTK3 创建的按钮时,python 开始执行命令,但我的所有应用程序都卡住了。我点击按钮的 python 代码是:

def on_next2_clicked(self,button):
cmd = "My Command"
proc = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE)
while True:
line = proc.stdout.read(2)
if not line:
break
self.fper = float(line)/100.0
self.ui.progressbar1.set_fraction(self.fper)
print "Done"

我还必须将命令输出设置为窗口中的进度条。任何人都可以帮助解决我的问题吗?我也尝试过在 python 中使用线程,但它也没有用......

最佳答案

从循环中运行主循环迭代:

def on_next2_clicked(self,button):
cmd = "My Command"
proc = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE)
while True:
line = proc.stdout.read(2)
if not line:
break
self.fper = float(line)/100.0
self.ui.progressbar1.set_fraction(self.fper)
while Gtk.events_pending():
Gtk.main_iteration() # runs the GTK main loop as needed
print "Done"

关于python - 在 python GTK3 中单击按钮后窗口卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11199057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com