Nov-03-2020, 09:37 PM
Hi
Using PyQt5, I try to create pushbuttons from a list in a loop. As an example, I extracted the following script (I'm fond of ancient greek)
Thank you to anybody explaining me how to have the second parameters of the tuples to be sent to the slot.
Arbiel
Using PyQt5, I try to create pushbuttons from a list in a loop. As an example, I extracted the following script (I'm fond of ancient greek)
#!/usr/bin/env python # -*- coding: utf-8 -*- # # from PyQt5 import QtCore, QtWidgets from PyQt5.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit, QPushButton, QApplication from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QMessageBox class Κοινή(QtWidgets.QWidget): def __init__(ἁυτόν): super(Κοινή,ἁυτόν).__init__() def init(ἁυτόν): zc=QHBoxLayout(ἁυτόν) zc.addStretch() ἁυτόν.lesboutons=[('Quitter','quit', True), ('Auteurs', 'aut', True), ('Vocabulaire', 'vocab', False), ('Textes', 'texte', True) ] for tpl in ἁυτόν.lesboutons: btn=QPushButton(tpl[0]) btn.setObjectName(tpl[1]) btn.setEnabled(tpl[2]) btn.clicked.connect(lambda : ἁυτόν.execut(tpl[1])) btn.clicked.connect(lambda cde=tpl[1] : ἁυτόν.execut(cde)) zc.addWidget(btn) zc.addStretch() def execut(ἁυτόν, cde): print(cde) def afficher(ἁυτόν, ὄνομα, χωρίον=None): if χωρίον==None: χωρίον=(250,200,800,300) ἁυτόν.setGeometry(χωρίον[0],χωρίον[1],χωρίον[2],χωρίον[3]) ἁυτόν.setWindowTitle(ὄνομα) ἁυτόν.show() def main(args): app = QtWidgets.QApplication(args) application=Κοινή() application.init() afficher(application,'Κοινή', [300,150,300,250]) app.exec() return 0 if __name__ == '__main__': import sys sys.exit(main(sys.argv))At launch, the window with the 4 buttons is displayed. Clicking on any active button sends two signals to execut. I have understood why the parameter of the first signal always is 'texte', but I do not understand why the parameter of the second one is a boolean.
Thank you to anybody explaining me how to have the second parameters of the tuples to be sent to the slot.
Arbiel