PyQt Window No Show

后端 未结 1 1543
故里飘歌
故里飘歌 2020-12-21 23:45

Upon calling the show method on simple the simple window does not show. Why doesn\'t my Simple window show. :(

import sys
from PyQt4 import QtGui


class Wid         


        
相关标签:
1条回答
  • 2020-12-22 00:21

    The problem with your code is that, simple in __init__ method of class Widget is a local variable, so as soon as the __init__ method finishes execution, the simple object is destroyed by the python Garbage Collector, thus the window does not appear because the object does not exist in the memory. To solve your problem, just add self at the starting of the simple variable to make it member variable.

    ...
    self.simple = Simple()
    button = QtGui.QPushButton("Button", self)
    button.clicked.connect(self.simple.show)
    ...
    
    0 讨论(0)
提交回复
热议问题