我放置在生成的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()