PyQt5-如何识别按下了哪个按钮

时间:2018-10-29 10:01:50

标签: python pyqt5

我正在寻找,看到人们在某些地方使用sender()并将其转换为文本sender.text()

像这样:

@pyqtSlot()
def on_click(self):
    sender = self.sender()
    printf(sender.text())
    self.openFileNameDialog(0)

但是我的代码退出了发送到sender.text()

我想将特定按钮传递给功能self.openFileNameDialog(0)

1 个答案:

答案 0 :(得分:0)

因此,这就是我在ekhumoro的帮助下使其工作的方式。

@pyqtSlot()
def on_click(self):
    self.openFileNameDialog(self.sender())

def openFileNameDialog(self, which_button):
    if which_button is pushButton:
        #do something
    if which_button is pushButton2:
        #do something
相关问题