1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import division
# Python 2.7
import sys
from PyQt4 import QtCore, QtGui
#############################################################################
class Fenetre(QtGui.QWidget):
def __init__(self, parent=None):
super(Fenetre, self).__init__(parent)
self.bouton1 = QtGui.QPushButton(u"bouton 1", self)
self.bouton2 = QtGui.QPushButton(u"bouton 2", self)
signalMapper = QtCore.QSignalMapper(self)
signalMapper.setMapping(self.bouton1, 1)
self.bouton1.clicked.connect(signalMapper.map)
signalMapper.setMapping(self.bouton2, 2)
self.bouton2.clicked.connect(signalMapper.map)
signalMapper.mapped.connect(self.choisirRepertoire)
posit = QtGui.QGridLayout()
posit.addWidget(self.bouton1, 0, 0)
posit.addWidget(self.bouton2, 1, 0)
self.setLayout(posit)
def choisirRepertoire(self, num):
QtGui.QMessageBox.information(self,
u"Bouton cliqué",
u"c'est le bouton %s" % num)
#############################################################################
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
fen = Fenetre()
fen.show()
sys.exit(app.exec_()) |
Partager