1

I want to set atribute QtRadioButton using name of the QtRadioButton from the string. But I'm not doing well. I also tried locals(). But it can only assign a value to a variable.

This works:

typ = "E"
locals()["self.pocetParciel"+typ] = 0
print(locals()["self.pocetParciel"+typ])

This doesn't work: locals()["self.radioButton"+typ].setEnabled(True)

Prints an error: KeyError: 'self.radioButtonE'

I also tried exec() but it didn't help. I thank you in advance for your help.

globals(), locals(), exec()

Stano
  • 7
  • 2

0 Answers0