Python已停止在PyQt应用程序中工作
代码如下:运行大约半分钟后,关闭窗口,弹出“Python已停止工作”对话框(您最好多次尝试) 我想知道为什么会这样?有什么解决办法吗? 使用PyQt4-4.11.3-gpl-Py3.4-Qt4.8.6-x32.exe在Windows上测试Python已停止在PyQt应用程序中工作,python,qt,pyqt,pyside,Python,Qt,Pyqt,Pyside,代码如下:运行大约半分钟后,关闭窗口,弹出“Python已停止工作”对话框(您最好多次尝试) 我想知道为什么会这样?有什么解决办法吗? 使用PyQt4-4.11.3-gpl-Py3.4-Qt4.8.6-x32.exe在Windows上测试 from PyQt4.QtCore import * from PyQt4.QtGui import * class MainWindow(QMainWindow): def __init__(self): super()._
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowIcon(QIcon("./wa.png"))
self.createTrayIcon()
def createTrayIcon(self):
self.trayIcon = QSystemTrayIcon()
self.trayIcon.setIcon(self.windowIcon())
self.trayIcon.show()
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
ui = MainWindow()
ui.show()
sys.exit(app.exec_())
我在linux上进行PyQt工作,因此可能存在差异,但通常我使用以下调用构造主窗口:
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
...
我可以在python3中运行您的代码,但退出后会出现分段错误。如果我将构造函数更改为我在上面指出的值,则不会再现故障
希望这有帮助您确定可以运行代码吗?没有参数的
super()
调用看起来是错误的,事实上,当我试图运行代码时,它抱怨它至少需要一个参数。@IosifSpulber该代码与py3一起工作