用pythonw打开没有控制台的pyqt程序(Open pyqt program without console with pythonw)

编程入门 行业动态 更新时间:2024-10-26 01:20:49
用pythonw打开没有控制台的pyqt程序(Open pyqt program without console with pythonw)

我有一个奇怪的问题。 我创建了一个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.

更多推荐

本文发布于:2023-07-16 07:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1125523.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   程序   pyqt   pythonw   program

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!