Python PyQT-从其他函数修改主窗口小部件
一个PyQT初学者问题。我想知道如何在主窗口类之外修改主窗口中的小部件。像这样:Python PyQT-从其他函数修改主窗口小部件,python,pyqt,Python,Pyqt,一个PyQT初学者问题。我想知道如何在主窗口类之外修改主窗口中的小部件。像这样: class MainWindow(QtGui.QMainWindow): def __init__(self, parent=None): super(MainWindow,self).__init__(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self)
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow,self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.progressBar.setMaximum(100)
self.ui.progressBar.setMinimum(0)
self.ui.progressBar.setValue(0)
self.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.slotDoStuff)
def slotDoStuff(self):
AnotherFunction()
def AnotherFunction():
modify progress bar here...
有没有办法做到这一点?我希望为各种主窗口操作对事件处理程序进行子类化,而不是将它们全部放在主窗口类中。谢谢 首先,有一种更好的方式将信号连接到PyQt上的插槽:
self.button.clicked.connect(self.method)
可以使用lambda函数向方法传递额外的参数
def do_stuff(arg)
#do stuff with arg
然后你打电话
self.button1.clicked.connect(lambda : do_stuff('btn one'))
self.button2.clicked.connect(lambda : do_stuff('btn two'))
您可以传递任何需要的内容,包括要修改的MainWindow实例