(PyQt5)QMainWindow没有显示任何小部件?

时间:2017-07-11 21:59:20

标签: python python-3.x pyqt pyqt5

我放置在生成的QMainWindow实例中的任何小部件都不显示,尽管窗口本身显示完全正常。谁能解释我做错了什么?

import sys
import random
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *


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


class First(QWidget):
    def __init__(self, parent=None):
        super(First, self).__init__(parent)
        #UI Stuff
        self.resize(250, 150)
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())
        self.setWindowTitle('FE: R')
        self.setWindowIcon(QIcon('icon.gif'))

        #Button Stuff
        btn1 = QPushButton("Button 1", self)
        btn1.move(30, 50)
        btn1.clicked.connect(self.button1_event)
        self.dialog = Second(self)
        self.show()
    def button1_event(self):
        self.dialog.show()


def main():
    app = QApplication(sys.argv)
    main = First()
    main.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

0 个答案:

没有答案