Calling Python GUI's from MATLAB using pyrunfile

조회 수: 2 (최근 30일)
Rajiv Kumar
Rajiv Kumar 2025년 2월 10일
편집: Rajiv Kumar 2025년 2월 14일
Hello Team
I have a python Pyside6 GUI. I have the requirement to call my python GUI from my MATLAB app designer GUI.
I did the same using pyenv -> pyrunfile. I call my dummy.py script by adding a callback to my app designer GUI in matlab. The callback in MATLAB .mlapp file basically uses pyrunfile to call my python GUI script and loads the pyside6 GUI.
As soon as the callback hits, my python GUI opens but goes into an unresponsive state. How do I avoid this so that my MATLAB GUI and python GUI works hand in hand?
Furthermore,I am doing an operation to write into my excel sheet using the python GUI. Again, when I call the GUI from MATLAB using pyrunfile (this time using the command window of MATLAB), the writing operation is sucessfully performed, but the file remains in an open state. I cannot delete the xlsx file until and unless i completely close my MATLAB since the file remains open in MATLAB even if i have properly close that file from python. How to solve this?

답변 (1개)

Karan Singh
Karan Singh 2025년 2월 12일
편집: Karan Singh 2025년 2월 12일
I think PySide6 expects to control the main thread, but MATLAB is also running its own event loop. When MATLAB calls "dummy.py" it waits for the Python script to finish execution. But since PySide6 is waiting for user interactions, MATLAB does not regain control, leading to an unresponsive GUI. The try can be to run your Python GUI in a separate process rather than in MATLAB’s process. Instead of calling your Python script using pyenv (which embeds Python in MATLAB), launch it as an external process.
  댓글 수: 1
Rajiv Kumar
Rajiv Kumar 2025년 2월 14일
편집: Rajiv Kumar 2025년 2월 14일
So, is there no other way apart from calling from a separate process?
Will this involve calling the python GUI from system command? Since that is the only way I could think of to run it in a separate process. Or is there any other method?
also, how does pyenv and pyrunfile differ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by