Question

In my pygtk app, I want to close current window after opening next window.

this is the code which i have written

#!/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()

when I click on next button it opens next window but it does not close my current window in background and current window go to hang in background after opening next window.

def next(self,widget):
   subprocess.call("fabfile.py", shell=True)
   self.win.destroy()

when i run this code in

window machine it is not closing existing window and

Linux machine it is giving this error.

/bin/sh: fabfile.py: command not found

Anyone let me know how to resolve this. Thanks...

Was it helpful?

Solution

Try this, I hope it will work but I am not sure,

import subprocess
subprocess.Popen(["fabfile.py"], bufsize=2048, shell=True,stdin=subprocess.PIPE, stdout=subprocess.PIPE)
self.win.destroy()

subprocess.Popen will open your 2nd window and close after current window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top