[Python] Running a function through a for loop with a change in the index in a variable...

Discussão em 'Python' iniciado por Stack, Abril 5, 2025.

  1. Stack

    Stack Membro Participativo

    There are 20 checkboxes in the user's window, in the code their name is checkbox_1, checkbox_2, ... checkbox_20. To activate all the checkboxes at the same time, I use this algorithm:

    def select_all_W(self):
    self.Ui.checkBox_1.setChecked(True)
    self.Ui.checkBox_2.setChecked(True)
    # .................................
    self.Ui.checkBox_20.setChecked(True)


    This makes the code very large and heavy. Is it possible to do the same thing through some function or, for example, through a loop:

    for i in range 20
    self.Ui.checkBox_.setChecked(True)


    In other words, how can you simplify the activation of a large number of window elements?

    Continue reading...

Compartilhe esta Página