【问题标题】:Widget not getting displayed in pyqt5小部件未在 pyqt5 中显示
【发布时间】:2018-02-10 18:24:42
【问题描述】:

我是 python 的新手,甚至是 PyQt 的新手。我的按钮小部件没有显示在窗口中。我确定我在这里犯了一个愚蠢的错误。

import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication

class Window(QWidget):

    def __init__(self):
        super(Window, self).__init__()
        self.setWindowTitle("Buttons")
        self.setGeometry(100, 100, 500, 500)
        self.show()
        self.main()

    def main(self):
        button = QPushButton('Quit', self)
        button.clicked.connect(QApplication.instance().quit)
        button.resize(button.sizeHint())
        button.move(150, 150)
        self.show()

def run():
    app = QApplication(sys.argv)
    GUI = Window()

    sys.exit(app.exec_())
run()

希望能提供帮助。

【问题讨论】:

    标签: python-3.x pyqt5


    【解决方案1】:

    在def main(self): 中,您在self 上致电show()。它应该是button.show()。

    【讨论】:

    • 解决了这个问题。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-13
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 2018-03-14
    • 2021-04-26
    相关资源
    最近更新 更多