EDIT 9: Before writing an answer saying to change Exec=/home/insertUsernameHere/volumeGUI/volumeGUI.py
to Exec=something or another
, the .desktop
file Exec=
code isn't the problem as it runs fine with gtk-launch
. The problem is that it doesn't run from Show Applications, it just does nothing. Also please watch my screen capture so you can see exactly what the problem is.
I’ve been trying (for a couple of hours now) to get a .desktop
file to run my python script, but when I click on the icon in the applications window, nothing happens.
Here’s my .desktop code:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=/home/insertUsernameHere/volumeGUI/volumeGUI.py
Name=Volume GUI
Icon=/home/insertUsernameHere/volumeGUI/volumeGUI_Logo.png
Note that when I run
/home/insertUsernameHere/volumeGUI/volumeGUI.py
in the terminal it works fine.
EDIT: Here's my python code
#!/usr/bin/env python3
from tkinter import *
from tkinter.font import *
import subprocess
top = Tk()
top.resizable(False, False)
top.title("Python Volume Controller")
padx = 10
pady = 10
myFont = Font(family = "helvetica", size = 16, weight = "bold")
volumeTextVariable = StringVar()
currentVolumeText = Label(top, textvariable = volumeTextVariable, font = myFont)
currentVolumeText.grid(row = 1, column = 0, columnspan = 2, padx=padx, pady=pady)
volumeIncrement = 2
def volumeUp(volume):
if (volume + volumeIncrement) <= 100:
subprocess.call("pactl set-sink-volume 0 +" + str(volumeIncrement) + r"%", shell=True)
volumeTextVariable.set("Current Volume: " + getVolume() + r"%")
def volumeDown(volume):
if (volume - volumeIncrement) >= 0:
subprocess.call("pactl set-sink-volume 0 -" + str(volumeIncrement) + r"%", shell=True)
volumeTextVariable.set("Current Volume: " + getVolume() + r"%")
def getVolume():
try:
volume = subprocess.Popen("amixer get Master |grep % |awk '{print $4}'|sed 's/[^0-9]//g'", stdout=subprocess.PIPE, shell=True).communicate()[0].decode("utf-8")[:-1]
except:
volume = -404
return volume
volumeTextVariable.set("Current Volume: " + getVolume() + r"%")
volUpButton = Button(top, text = "Volume Up", command = lambda: volumeUp(int(getVolume())), font = myFont)
volDownButton = Button(top, text = "Volume Down", command = lambda: volumeDown(int(getVolume())), font = myFont)
volUpButton.grid(row = 2, column = 1, padx=padx, pady=pady)
volDownButton.grid(row = 2, column = 0, padx=padx, pady=pady)
top.mainloop()
EDIT 6: GIF of me running the .desktop
file in the command line with gtk-launch volumeGUI.desktop
and it working, but not working when trying to launch it from Show Applications
Screen Capture
EDIT 7: I have since improved my python code: https://paste.ubuntu.com/p/QF6PVrSPSy/
EDIT 8: I changed Exec=/home/insertUsernameHere/volumeGUI/volumeGUI.py
to Exec=bash -c "/home/insertUsernameHere/volumeGUI/volumeGUI.py 2>&1 > ~/logfile.txt"
as per a suggestion and when I either run it with gtk-launch
or try and run it from Show Applications the log file is empty.
.desktop
file with gtk-launch in the command line as per a suggestion but I'm still unable to launch it by clicking on it in either Show Applications, the bar down the left of the screen, or Files.gtk-launch
exactly does, but could you please confirm/double check the paths match exactly, paste the icon path in a browser. Just to make sure, but you are aware you need to double-click on the icon if it is on your desktop, to show it in the launcher, it needs to be in~/.local/share/applications
, right? As said, it works instantly here.~/.local/share/applications
and I can see it in Show Applications, if you watch the screen capture GIF in edit 6 you'll see exactly what happens. edit: I don't know whatgtk-launch
does either, it was suggested in the comments that have since been moved to a chat.