sonik-88
sonik-88

Reputation: 93

Run Python Script through Shell Script by Double Click

I have a runGUI.sh script and I want to run a Python script through it. The Python Script is a GUI.py that I want to make it run as an App, by either double clicking the Shell script or the Python Script itself (ideally I would like to have both ways).

I tried everything that others recommend:

The result is the same. If I double click the GUI.py or the runGUI.sh, and because they are executable, I get the options:

Options when double clicking

Regardless of "Run in Terminal" or "Run", nothing happens.

If I run either scripts through terminal, like ./GUI.py or runGUI.sh, the Python file works fine and the GUI is opening in both cases.

Is there a way to open this GUI by double clicking the Shell or Python scripts?

I am using Ubuntu 16.04, standard Gnome, have installed Zshell if this helps and I built the Python GUI with the Tkinter module.

Upvotes: 1

Views: 6387

Answers (2)

Bigweld
Bigweld

Reputation: 26

Diego is mostly correct, but they left out one important detail that will cause it to fail. I am assuming you are using a python terminal application. It should look more like this:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=My GUI
Exec=python3 /path/to/GUI.py
Terminal=true

The Terminal=true makes it so it actually runs when you click on it. Also, put your python alias (python3,py,python,etc.) before it. Lastly, if you don't want an icon, just omit it rather than putting Icon=.

I know this is an old question, but I would have forgotten it too if I ran into this issue any less recently.

Upvotes: 1

Diego Torres Milano
Diego Torres Milano

Reputation: 69248

Create a file name mygui.desktop in ~/.local/share/applications

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=My GUI
Icon=
Exec=/path/to/GUI.py

and then mygui will be appearing as an application that you can launch clicking it.

Upvotes: 3

Related Questions