I am using PyQt to create a GUI and need to create a periodic table made of buttons. Bellow is part of the code. Each button will require the following code in the method mainLayout(self).
class App(QMainWindow):
def __init___(self):
...
def mainLayout(self):
Element1 = QPushButton('shortname', self)
Element1.setToolTip('longname')
Element1.setCheckable(True)
Element1.resize(50, 50)
Element1.move(x, y)
Element1.clicked.connect(self.Element1_click)
This is a lot of repetitive code for one button when there will be 118 buttons. I made a GUI in the past which had this same problem and I remember I solved the issue with creating another class which I passed the argument for the unique attributes of each button.
I had something like this in mind where LayoutElm is a class.
LayoutElm(Element1 ,'shortname', 'longname', x, y, Element1_click)
Any ideas would be greatly appreciated.