PyQt5 designer gui and iterate/loop over QPushButton [duplicate]
Asked Answered
W

0

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

Worst answered 6/5, 2020 at 19:7 Comment(3)
use for letter in "ABCDE": getattr(self, letter).clicked.connect(lambda checked, letter=letter: foo(letter))Dinitrobenzene
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 ?Worst
#33984480 this one helped tooWorst

© 2022 - 2024 — McMap. All rights reserved.