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_() 
复制代码

posted @ 2017-09-23 10:52  Dsp Tian  阅读(680)  评论(0编辑  收藏  举报