我有一个奇怪的问题。 我创建了一个GUI程序,使用WinPython-64bit-3.3.2.3在"spyder"运行没有问题,现在我想在没有控制台弹出的情况下运行它,我尝试使用pythonw.exe 。
当我将GUI保存为gui.pyw我可以通过右键单击使用PythonWin打开它,并使用edit with PythonWin但只需双击即可使我的GUI弹出不到一秒钟,然后退出程序。
这与我的GUI编程有关吗? “结构”就是这个:
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()我也尝试使用cx_freeze获取.exe并尝试按照此处所述进行构建Cx_Freeze :我遇到了同样的问题:GUI的主窗口弹出并再次消失
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
最满意答案
只需在代码末尾添加app.exec_() 。 您的代码在Spyder中运行良好,因为Spyder使用PyQt并且已经运行了主循环事件。
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.
更多推荐
发布评论