Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash脚本运行时的python弹出窗口_Python_User Interface_Glade - Fatal编程技术网

bash脚本运行时的python弹出窗口

bash脚本运行时的python弹出窗口,python,user-interface,glade,Python,User Interface,Glade,我为一个应用程序制作了一个简单的PyGTK-GladeGUI。我制作了这个按钮,点击按钮调用bash脚本。 我想在bash脚本运行时显示一个弹出窗口,并在完成后隐藏它。我在Glade中创建了名为runningWindow的窗口,并编写了以下代码: def on_button1_clicked(self,widget): self.glade.get_object("runningWindow").show() os.system('bash run.sh') self.glad

我为一个应用程序制作了一个简单的PyGTK-GladeGUI。我制作了这个按钮,点击按钮调用bash脚本。 我想在bash脚本运行时显示一个弹出窗口,并在完成后隐藏它。我在Glade中创建了名为runningWindow的窗口,并编写了以下代码:

def on_button1_clicked(self,widget):
   self.glade.get_object("runningWindow").show()
   os.system('bash run.sh')
   self.glade.get_object("runningWindow").hide()
此代码在run.sh运行时不显示任何内容。如果删除hide()行,窗口将正确显示,但仅在run.sh进程完成后显示

启动GUI的init函数:

def __init__(self):
        self.gladefile = "MyFile.glade" 
        self.glade = gtk.Builder()
        self.glade.add_from_file(self.gladefile)
        self.glade.connect_signals(self)
        self.glade.get_object("MainWindow").show_all()
如何在调用os.system之前显示窗口?
谢谢你的帮助

您可能希望查看子流程模块,并在后台任务中运行子流程。

我无法解决这个问题,但我可以绕过它。也许其他人会觉得它很有用:

首先,应该使用subprocess.Popen()而不是subprocess.call()。它会自动将子流程置于后台,因此会显示“正在运行”窗口。问题是如果我不删除.hide()命令,窗口弹出后立即消失。否则,当跑步结束时,我无法隐藏窗口

为了解决这个问题,我在一个新文件(runningWindow.glade和runningWindow.py)中创建了runningWindow

然后,我创建了一个包装器bash脚本,它说:

python runningWindow.py &
pid=$!
bash run.sh
kill pid
并使用主python脚本中的subprocess.Popen()调用此bash脚本