Calling Python GUI's from MATLAB using pyrunfile

40 ビュー (過去 30 日間)
Rajiv Kumar
Rajiv Kumar 2025 年 2 月 10 日 9:37
編集済み: Rajiv Kumar 2025 年 2 月 14 日 12:44
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 日 10:09
編集済み: Karan Singh 2025 年 2 月 12 日 10:10
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 日 6:57
編集済み: Rajiv Kumar 2025 年 2 月 14 日 12:43
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 Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by