【问题标题】:how to call the function when button is clicked using pyqt5 [duplicate]使用pyqt5单击按钮时如何调用该函数[重复]
【发布时间】:2020-03-09 15:19:02
【问题描述】:

当我想点击按钮时我想调用该函数我不明白我在做什么错

但它给了我下面给出的错误

TypeError: native Qt signal is not callable

class MyFirstWindow(QMainWindow):
    def __init__(self):
        self.Label = None
        self.Button = None
        super(MyFirstWindow, self).__init__()
        self.setGeometry(200, 200, 500, 500)
        self.setWindowTitle("My First Window GUI Application")
        self.ShowWidgets()

    def ShowWidgets(self):
        try:
            self.Label = QtWidgets.QLabel(self)
            self.Button = QtWidgets.QPushButton(self)
            self.Label.setText("My Name is Umair!")
            self.Label.move(170,70)
            self.Button.setText("Click Here")
            self.Button.move(160,30)
            self.Button.clicked(self.BtnClicked())
        except Exception as e:
            print(str(e))


    def BtnClicked(self):
        self.Label.setText("Label Text is Changed")


def ShowWindow():
    app = QApplication(sys.argv)
    win = MyFirstWindow()
    win.show()
    sys.exit(app.exec_())


ShowWindow()

【问题讨论】:

  • button.clicked.connect(method) 查看信号和槽
  • 那个方法也不起作用它也给我一个错误
  • @UmairMubeen 更改为 self.Button.clicked.connect(self.BtnClicked)

标签: python-3.x pyqt5


【解决方案1】:

试试:self.Button.clicked.connect(self.BtnClicked)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    • 2014-04-25
    • 2020-07-29
    • 2021-05-05
    • 2013-02-26
    • 2014-01-11
    相关资源
    最近更新 更多