[PyQt] multiple signal connect

Ruben Fonseca rf at 7syntax.com
Wed Aug 20 16:17:29 BST 2008


Hi,

I'm having a problem developing my first Python Qt4 app and I thought
you could help me.

I have a bunch of buttons that I want to watch for the "clicked()"
signal.

Since the handling is the same for all buttons I decided to write
something like this

----------
for button in [self.button_1, self.button_2, ..., self.button_0]:
   QtCore.QObject.connect(button, QtCore.SIGNAL('clicked()'), lambda:
self.button_clicked(button))

def button_clicked(self, number):
   print "Received a signal from %s" % number.objectName()
----------

However, every time I click on a button I got on the console

"Received a signal from button_0"

regardless the button I click... So I'm guessing something's wrong with
my lambda function.

What's the best way of solving this particular problem in Python?

Thank you for you support
Ruben Fonseca
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080820/a3b130bc/attachment.bin


More information about the PyQt mailing list