PyQt4(簡單訊號槽)

Dsp Tian發表於2017-09-23
複製程式碼
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_() 
複製程式碼

相關文章