【发布时间】:2016-10-13 17:18:06
【问题描述】:
如何将一个文件中的 pyqt 按钮信号连接到另一个 python 文件中的函数?我尝试了各种方法,但似乎没有任何效果。 这是第一个文件:
from PyQt4 import QtGui
from PyQt4.QtGui import QMainWindow
from MainUIFile import Ui_Main
from pythonfile import myOutsideFunction
class MainWindow(QMainWindow,Ui_file):
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self)
self.btn.clicked.connect(myOutsideFunction())
第一个调用的第二个文件:
def myOutsideFunction(self):
# Do some stuff here
我该怎么做呢?
【问题讨论】:
-
我也有同样的问题。你最后解决了吗?
-
我也遇到了同样的问题。我可以通过将函数放入 mixin 并让
MainWindow从 mixin 继承来修复它(例如class MainWindow(QMainWindow, EventsMixin))