kezzos
kezzos

Reputation: 3221

Pyside UI pops up and then disappears when run from cmd before it can be used?

I am fairly new to python and have made a simple UI using pyside. When run from inside the anaconda IDE the UI works fine, but when I run it using anaconda from the command line \python.exe 'runquacker.py' the UI flashes up and disappears immediately. The initial script is:

from PySide.QtCore import *
from PySide.QtGui import *
import sys
import quacker

class MainDialog(QDialog, quacker.Ui_Dialog):    
    def __init__(self, parent=None):
        super(MainDialog, self).__init__(parent)
        self.setupUi(self)

app = QApplication(sys.argv)
form = MainDialog()
form.show()

The rest of the UI is in quacker.py which collects a bunch of variables from the user, before executing a further analysis.py program using a subprocesscall. The variables are all passed in this way because thats the only way I could get pyside to work with my script! e.g. For two variables 'plots' and 'block':

subprocess.call([sys.executable, 'd:\\py\\anaconda\\analysis.py', str(plots), str(block)], shell=True)

Ive tried putting a raw_input('Blah..') in a few places but it just causes the program to hang or nothing at all.

Using \python.exe -i runquacker.py also causes the program to hang.

Thanks

Upvotes: 0

Views: 374

Answers (1)

Alvaro Fuentes
Alvaro Fuentes

Reputation: 17455

You need to add this line at the end of your script: app.exec_() That's because you need to actually execute your Qt application if you whant to see something. I'm not pretty sure why it works in Anaconda but if you are using some IDE like Spyder I think it works because Spyder is already running in Qt (so it called QApplication.exec_ before).

Upvotes: 2

Related Questions