0

I'm trying to find a way to substitute the name of the object in "self". Is it even possible to do this? It's just that I have a lot of checkboxes, when turned on, other elements should be activated (spinboxes, comboboxes, etc.). I consider it impractical to write a check for each object. I thought it would make the cycle more logical, but it doesn't work.

        for item in self.findChildren(QtWidgets.QCheckBox):
            if item.isChecked():
                x = item.objectName().split('_')[1]
                self.sb + f".{x}." + setDisabled()

"self.sb" is a "spanbox. the code is just an example of what I want to do. I know that I substituted the concatenation incorrectly.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
alek vertysh
  • 187
  • 4
  • 10

1 Answers1

0

I've find out.

        for item in self.findChildren(QtWidgets.QCheckBox):
        if item.isChecked():
            try:
                name = f"sb_{item.objectName().split('_')[1]}"
                getattr(self, f"{name}").setDisabled(False)
            except Exception as e:
                print('e1', e)
                pass
        elif item.isChecked() is False:
            try:
                name = f"sb_{item.objectName().split('_')[1]}"
                getattr(self, f"{name}").setDisabled(True)
            except Exception as e:
                print('e2', e)
                pass

Anyway, thanks.

alek vertysh
  • 187
  • 4
  • 10