【发布时间】:2023-03-31 02:37:02
【问题描述】:
在我的 pygtk 应用程序中,我想在打开下一个窗口后关闭当前窗口。
这是我写的代码
#!/usr/bin/env python
# example base.py
import pygtk
pygtk.require('2.0')
import gtk
import subprocess
class Base:
def next(self,widget):
subprocess.call('fabfile.py', shell=True)
self.window.destroy()
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_size_request(200,200)
self.button = gtk.Button("Next")
self.button.show()
self.button.connect("clicked", self.next)
self.window.add(self.button)
self.window.show()
def main(self):
gtk.main()
print __name__
if __name__ == "__main__":
base = Base()
base.main()
当我点击下一个按钮时,它会打开下一个窗口,但它不会在后台关闭我当前的窗口,并且当前窗口会在打开下一个窗口后挂在后台。
def next(self,widget):
subprocess.call("fabfile.py", shell=True)
self.win.destroy()
当我在
中运行这段代码时window machine 它没有关闭现有窗口并且
Linux machine 它给出了这个错误。
/bin/sh: fabfile.py: command not found
谁能告诉我如何解决这个问题。谢谢...
【问题讨论】:
-
在 linux 上:
subprocess.call('fabfile.py', shell=True)应该是subprocess.call('.\fabfile.py', shell=True)。这与搜索脚本时不包含当前工作目录有关。 -
我已经尝试过你的建议,但它给出了同样的错误。你有任何其他的解决办法。
-
@cstrutton:
'\f'是单个字符(ASCII Formfeed)。您需要转义反斜杠,例如,使用原始字符串文字r'\f'(两个字符)。无论如何,您可能指的是'./local_command'(如果您不在Windows上)。而且通常fabfile.py不是直接调用而是使用fab命令。subprocess.Popen('fab')无需等待完成即可启动fab命令。
标签: python python-2.7 subprocess pygtk