我是 Python 新手。我使用 PyQt 创建了一个按钮,并希望通过单击同一个按钮调用两个单独的函数
QtCore.QObject.connect(self.start, QtCore.SIGNAL('clicked()'), self.trial,self.trial2)
最佳答案
您可以只连接信号两次,例如:
QtCore.QObject.connect(self.start, QtCore.SIGNAL('clicked()'), self.trial)
QtCore.QObject.connect(self.start, QtCore.SIGNAL('clicked()'), self.trial2)
当信号发出时,这两个函数都会被调用。根据文档:
If a signal is connected to several slots, the slots are activated in the same order in which the connections were made, when the signal is emitted.
关于Python在PyQt中一键调用两个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32285370/