from PyQt4 import QtGui, QtCore
class MyButton(QtGui.QPushButton):
myclicked = QtCore.pyqtSignal(int)
def __init__(self, _id, *args, **kwargs):
QtGui.QPushButton.__init__(self, *args, **kwargs)
self._id = _id
self.connect(self, QtCore.SIGNAL("clicked()"), self.emitMyclicked)
def emitMyclicked(self):
self.myclicked.emit(self._id)
app = QtGui.QApplication([])
w = QtGui.QWidget()
w.resize(100, 100)
def showMsg(_id):
QtGui.QMessageBox.information(w, u"信息", u"查看 %d" % _id)
btn = MyButton(1, u"查看1", w)
w.connect(btn, QtCore.SIGNAL("myclicked(int)"), showMsg)
btn2 = MyButton(2, u"查看2", w)
btn2.move(0, 30)
w.connect(btn2, QtCore.SIGNAL("myclicked(int)"), showMsg)
w.show()
app.exec_()
上面例子可以看出, QObject.emit 发送带参数的信号时要携带参数. 当然上面例子也可以用下面方式来写
from PyQt4 import QtGui, QtCore
class MyButton(QtGui.QPushButton):
def __init__(self, _id, *args, **kwargs):
self._id = _id
QtGui.QPushButton.__init__(self, *args, **kwargs)
self.connect(self, QtCore.SIGNAL("clicked()"), self.emitClicked)
def emitClicked(self):
self.emit(QtCore.SIGNAL("myclicked(int)"), self._id)
app = QtGui.QApplication([])
w = QtGui.QWidget()
w.resize(100, 100)
def showMsg(_id):
QtGui.QMessageBox.information(w, u"信息", u"查看 %d" % _id)
btn = MyButton(1, u"查看1", w)
w.connect(btn, QtCore.SIGNAL("myclicked(int)"), showMsg)
btn2 = MyButton(2, u"查看2", w)
btn2.move(0, 30)
w.connect(btn2, QtCore.SIGNAL("myclicked(int)"), showMsg)
w.show()
app.exec_()
打开手机,解锁,进入桌面。长按一个软件中的图标,把它拖到另一个软件的图标处,使两个图标重合,这样就建成一个文件夹。桌面应用程序就是GUI程序,是采用图形方式显示的计算机 *** 作用户界面。
图形用户界面是一种人与计算机通信的界面显示格式,允许用户使用鼠标等输入设备 *** 纵屏幕上的图标或菜单选项,以选择命令、调用文件、启动程序或执行其它一些日常任务。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)