Connecting slots and events in PyQt4 in a loop
Posted
by
LukaD
on Stack Overflow
See other posts from Stack Overflow
or by LukaD
Published on 2011-01-02T14:47:47Z
Indexed on
2011/01/02
14:54 UTC
Read the original article
Hit count: 247
Im trying to build a calculator with PyQt4 and connecting the 'clicked()' signals from the buttons doesn't as expected. Im creating my buttons for the numbers inside a for loop where i try to connect them afterwards.
def __init__(self):
for i in range(0,10):
self._numberButtons += [QPushButton(str(i), self)]
self.connect(self._numberButtons[i], SIGNAL('clicked()'),
lambda : self._number(i))
def _number(self, x):
print(x)
When I click on the buttons all of them print out '9'. Why is that so and how can i fix this?
© Stack Overflow or respective owner