Calling Python GUI's from MATLAB using pyrunfile

1 vue (au cours des 30 derniers jours)
Rajiv Kumar
Rajiv Kumar le 10 Fév 2025
Modifié(e) : Rajiv Kumar le 14 Fév 2025
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?

Réponses (1)

Karan Singh
Karan Singh le 12 Fév 2025
Modifié(e) : Karan Singh le 12 Fév 2025
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 commentaire
Rajiv Kumar
Rajiv Kumar le 14 Fév 2025
Modifié(e) : Rajiv Kumar le 14 Fév 2025
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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by