Setting widget variable from --python-code on Slicer.exe start

Hey,
Apologies it took me a while to respond, thank you so much for your help.
For future reference to those who stumble on this post I would like to elaborate on the solution.
@lassoan thank you for the suggestion of improving on the string formatting. Use of

“\n” and “\t”

within the string was not a problem. Although for future reference it is good to know that I can separate commands inline with semicolon “;”
The real problem was that I was trying to set

self.host_port

by accessing

slicer.util.getModule(‘BlenderMonitor’).widgetRepresentation().self().[widget init var]

Reviewing @lassoan suggestion, widget class functions are more appropriately accessed by the

slicer.util.getModuleWidget().[widget class method] ()

method. When I switched to getModuleWidget() and wrapped self.host_port variable in the self.connect_to_blender() method I was able to pass and set self.host_port on widget startup.

TL;DR @lassoan code suggestions worked well, use of semicolon was not necessary and use of \n and \t in string formatting is acceptable when --python-code

1 Like