Python Forum
[PyQt] Call object with string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Call object with string
#5
The only reasons for giving widgets names is so you can reference them in a style sheet or you used a designer to make your panels. Otherwise you should create structure to organize your widgets to make them easy to use.

I do not like building strings using "+" and now use f'strings. In your code I would replace
string = 'FormulationName' + cb.objectName()[11:]
code_string = 'self.' + string + '.text()'
with this:
code_string = f'self.FormulationName{cb.objectName()[11:]}.text()'
Reply


Messages In This Thread
Call object with string - by PEGylated_User - Oct-27-2020, 05:44 PM
RE: Call object with string - by ndc85430 - Oct-27-2020, 06:10 PM
RE: Call object with string - by PEGylated_User - Oct-27-2020, 06:23 PM
RE: Call object with string - by Axel_Erfurt - Oct-27-2020, 06:50 PM
RE: Call object with string - by deanhystad - Oct-27-2020, 09:36 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020