1
votes

code like the following .After it running for about half a minute ,then close the window, then the "Python has stopped working" dialog pops up(you had better try more than once. ) I wonder why this happen ?any solution to this ? ​ Tested on Windows with PyQt4-4.11.3-gpl-Py3.4-Qt4.8.6-x32.exe

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_())
1
Are you sure you can run the code? The super() call with no argument looked wrong, and indeed when I try to run the code it complains that it requires at least one argument.Iosif Spulber
@IosifSpulber the code works with py3iMath

1 Answers

0
votes

I do my PyQt work on linux, so there might be differences, but usually I construct my MainWindow with the following call:

class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        ...

I can run your code in python3, but after I exit I get the Segmentation Fault. If I change the constructor to what I indicated above the Fault is not reproduced.

Hope this helps