PyQt4(简单信号槽)

复制代码
import sys
from PyQt4 import QtCore, QtGui

class myWidget(QtGui.QWidget):
    def __init__(self):
        super(myWidget, self).__init__()
        self.setWindowTitle("test")
        self.resize(300, 200)
        self.lab = QtGui.QLabel("label")
        self.btn = QtGui.QPushButton("button")
        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.lab)
        hbox.addWidget(self.btn)
        self.setLayout(hbox)
        self.connect(self.btn, QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('OnClick()'))


    @QtCore.pyqtSlot()
    def OnClick(self):
        self.lab.setText("sdfasdf")


app = QtGui.QApplication(sys.argv)
wi = myWidget()
wi.show()
app.exec_() 
复制代码

PyQt4(简单信号槽)_第1张图片

转载于:https://www.cnblogs.com/tiandsp/p/7580563.html

你可能感兴趣的:(PyQt4(简单信号槽))