0

Could you help me please. I have PyQt5 UI. And I have dynamic UI which depends on user. So, for example I have QSpinBox element and its option in string that stores in json file:

uiElement:"QtWidgets.QSpinBox()",
option:".setMaximum(10)"

How I can concatenate it in python code? I mean, I have eval function to call QtWidgets.QSpinBox() from json and it works fine, but how I can add to those QSpinBox my second part (".setMaximum(10)")?

For example:

a=eval(json["uiElement"]) #we get our QSpinBox
b=json["option"] #our option

#This works fine:
a.setMaximum(10)

#But this of course no
a+b
  • Can you provide a minimal reproducible example?https://stackoverflow.com/help/minimal-reproducible-example – bbasaran Apr 21 '22 at 15:05
  • It's [insanely bad practice](https://stackoverflow.com/q/1832940/984421) to eval arbitrary strings taken from user input, and totally unnecessary. Use [getattr](https://docs.python.org/3/library/functions.html#getattr) instead. – ekhumoro Apr 21 '22 at 15:53

0 Answers0