8

I have been learning Tkinter, so I took some of my Python programs and made them work in a window.

By chance, I saw this way of launching a Python program on Stack Overflow, so I tried it.

Then I made an icon and put this code in /home/pedro/.local/share/applications/

[Desktop Entry]  
Type=Application   
Terminal=false     
Name=Mark CW and HW  
Exec=/home/pedro/myPython/tkinter/answersToExcel2.py  
Icon=/home/pedro/icons/icon4.png   
StartupWMClass=myTkApp

I have never done anything like this before, but to my surprise, it works fine! I locked the icon to my launcher. Now I can start my Tkinter window anytime from the launcher.

My question is: Where can I get more information about what should, must or can be in this kind of [Desktop Entry]?

Also, if for some reason the python code fails (not happened yet, I test thoroughly in Idle first) will an error message be written somewhere?

pomsky
  • 68,507
Pedroski
  • 375
  • FYI: In KDE (and probably elsewhere), you can edit the Application Menu and add an entry for any executable. Once it's in your menu, you can drag it to your desktop or to your panel and you're done. It may not have all the bells and whistles, but it works. Just another way to do it without any additional programs or editing .desktop files. The monster spec for all this is https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html. – Joe Aug 06 '20 at 03:04
  • I have a number of bash scripts that I have turned into GUI programs by generating .desktop files for them and having them call out to a GUI dialog manager (yad.) For the most part, it works great. – Joe Aug 06 '20 at 03:35

2 Answers2

10

A .desktop launcher follows freedesktop.org desktop entry and menu standards. Some standard keys are:

  • Name= Specific name of the application.
  • Comment= A short description of the application.
  • Exec= Command to launch the application.
  • Icon= Icon for the application (an icon provided by your icon theme or an absolute path to an image file).
  • Type= Types of desktop entries, supported ones are Application, Link or Directory.
  • Terminal= true/false, whether the application runs in a terminal window.
  • Categories= Categories to which the application belongs (Main Categories, Additional Categories and Reserved Categories).
  • StartupWMClass= is a very useful one.

For a detailed list of specifications, visit freedesktop.org.


P.S. Various GUI applications which can be used to create application launchers, e.g. 'Main Menu' (aka alacarte) or 'MenuLibre' (menulibre), just creates a .desktop file in an appropriate location (e.g. ~/.local/share/applications/) under the hood.

pomsky
  • 68,507
1

The other part of your question:

Programs that are designed for the CLI (and some GUI ones too) usually write all their informational and error messages to stdout and stderr which are normally connected to a terminal/CLI. When you start such programs from a GUI, these streams are usually connected to bit buckets (/dev/null) and all such messages are lost.

When a GUI program misbehaves, a handy trick is to run it from within a terminal. Then, any such messages it issues will have a place to go and may tell you why things aren't working as desired.

A number of GUI programs are quite loquacious when run this way.

In KDE (and probably elsewhere), the Application Menu Editor allows you to select an option for an entry to run in a terminal. This causes a terminal window to automatically open when you run such an entry. When the program is done, the terminal window closes, so if you need to see the final messages, you have to add something that pauses the program or a wrapper script at the end so you can read the messages before they disappear.

Joe
  • 1,884