Calling Python GUI's from MATLAB using pyrunfile
40 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
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.
参考
カテゴリ
Help Center および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!