質問

i have a strange problem. I created a GUI program which runs in "spyder" with WinPython-64bit-3.3.2.3 with no problems, now i want to run it without the console to pop up and i try to use pythonw.exe.

When i save my GUI as gui.pyw i can open it with PythonWin by right clicking and use edit with PythonWin but simply double-clicking will make my GUI pop up for less than a second and exit the program afterwards.

Does this have to do with my GUI programming? the "structure" is this one:

import sys 
from PyQt4 import QtGui, QtCore, Qt  
from Main_Window_v2 import Ui_Dialog as Dlg

class MeinDialog(QtGui.QDialog, Dlg): 
    def __init__(self): 
        QtGui.QDialog.__init__(self) 
        self.setupUi(self)
    
  
        self.connect(self.buttonOK, 
            QtCore.SIGNAL("clicked()"), self.onOK) 
        self.connect(self.buttonAbbrechen, 
            QtCore.SIGNAL("clicked()"), self.onClose)                  
        self.connect(self.buttonsql, 
            QtCore.SIGNAL("clicked()"), self.onsql)

    def onsql(self):
   
        login=self.login_text_box.toPlainText()
   
        from calc import get_variables #sql query
        self.get_variables=get_variables(login)
        #calls a class´ __init__ in another file in my direcotry

    
    def onOK(self):
        login=self.login_text_box.toPlainText()

        self.get_variables.plot(login)
        #calls another function in my class "calc"
    def onClose(self): 
        print("bye!")
        self.close()

app = QtGui.QApplication(sys.argv) 
dialog = MeinDialog() 
dialog.show()

I also tried to get an .exe using cx_freeze and after trying to making build as described here Cx_Freeze: I have the same problem: The Main-Window of the GUI pops up and disappears again

役に立ちましたか?

解決

Just add app.exec_() at the end of your code. Your code was running well in Spyder because Spyder uses PyQt and had the main loop of events already running.

他のヒント

You should add app.exex_() at the end of your code, it is used to dispatch all PyQt GUI threads message or other threads info message.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top