0

Hi I have a GUI with 26 QPushButtons named A to Z, using uicload I load into my Main class

is there any way to loop over them to end up with something

self.A.clicked.connect(self.foo(A))
# ..
self.Z.clicked.connect(self.foo(Z))

tried different ways but I end up always with either a syntax error or a

AttributeError: 'Main' object has no attribute 'button' (button = i for i in letters)

of course using:

just

self.A.clicked.connect(self.foo(A))

it works but not the loop (like for i in list, where list is names of the button A,B,C ... Z

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
pippo1980
  • 2,181
  • 3
  • 14
  • 30
  • 1
    use `for letter in "ABCDE":` `getattr(self, letter).clicked.connect(lambda checked, letter=letter: foo(letter))` – eyllanesc May 06 '20 at 19:30
  • Hi thank yhou again, thats what I was looking for, kind of understood the getattr(self, letter), somehow I'll figure out the the need of lambda too. But lambda checked and the need of letter=letter is quite difficult to me have you got some reading about it, other than the two links above ? – pippo1980 May 07 '20 at 14:22
  • https://stackoverflow.com/questions/33983980/lambda-in-for-loop-only-takes-last-value this one helped too – pippo1980 May 07 '20 at 18:24

0 Answers0