Python在PyQt中一键调用两个函数

标签 python qt pyqt

我是 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/

相关文章:

python - 为什么 numpy 数组中相同索引选择的输出存在差异

python - 将数据和标签拆分为 pandas 数据框中的两个单独的列

c++ - Qt Creator 中的 Visual Studio 解决方案

c++ - 将参数绑定(bind)到信号/槽

python - pyqt:在 pyqt 中将多个信号连接到同一函数的正确方法(QSignalMapper 不适用)

python - 使用 Python for PyQt WebEngine 授予对 Cam & Mic 的访问权限

python - pyqt webkit + divx 网络播放器

python - 解释通过串行端口接收到的字节

python - 为 beutifulsoup4 python 添加延迟

c++ - 逐行读取文件与读取整个文件时的性能