Calling Python GUI's from MATLAB using pyrunfile

1 visualización (últimos 30 días)
Rajiv Kumar
Rajiv Kumar el 10 de Feb. de 2025
Editada: Rajiv Kumar el 14 de Feb. de 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?

Respuestas (1)

Karan Singh
Karan Singh el 12 de Feb. de 2025
Editada: Karan Singh el 12 de Feb. de 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 comentario
Rajiv Kumar
Rajiv Kumar el 14 de Feb. de 2025
Editada: Rajiv Kumar el 14 de Feb. de 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?

Iniciar sesión para comentar.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by