I am writing a python program that uses Tkinter for UI. I have to separate python files: interface.py and script.py. The script.py contains a code which calls a matlab script using matlab.engine module. The interface.py contains UI elements should call script.py when I press a certain button i.e. after I press a button in my program it runs matlab.scripts specified in script.py. However when I run interface.py, even though I just import script.py without actually calling its functions, it still starts matlab.engine on the program startup, as I understand it compiles and interpetes script.py when I import it. What I need is that matlab.engine written inside a function in script.py will be called when I want it to and not during the program startup.
Here is script.py:
import matlab.engine
def implement():
eng = matlab.engine.start_matlab()
eng.matlab_script(nargout=0)
eng.quit()
Here is interface.py snippet containing the function and the button:
def analyze():
import script
script.implement()
analyzeButton = Button(self, text = "Analyze ->", bg='#0D0628', width=10, height=2, command = analyze())