How to write an application for the system tray in Linux

Question:

How do I write my application so it’ll live in the system tray on Linux? In fact, just like CheckGmail.

As with CheckGmail, I’d also like some sort of popup box to appear when I hover the tray icon.

Is there an API, class or something for doing this? All I’m able to find seems to be for Windows.

If I have to be language specific, then preferably in C/C++ but a solution in Python will most likely also do.

Thanks.

Asked By: user50685

||

Answers:

python-eggtrayicon

here’s the example that comes with the debian package python-eggtrayicon in debian/testing…

#!/usr/bin/python
import pygtk
pygtk.require("2.0")
import gtk
import egg.trayicon
t = egg.trayicon.TrayIcon("MyFirstTrayIcon")
t.add(gtk.Label("Hello"))
t.show_all()
gtk.main()

It just shows a label in the notification area . (Search on that, and you’ll probably get much better hits…)

Answered By: Anders Eurenius

Qt is cross platform and has support for the system tray. Its Python bindings are pretty good as well. See the example application for further details.

Answered By: Kaleb Pederson

The Qt framework contains a QSystemTrayIcon class. This means that you can write an application in C++ or Python (or any other language with Qt bindings, including C#, Ada, Pascal, Perl, PHP and Ruby) and run your application on Windows, Linux, Mac or any other supported Qt operating system. I should add that Qt applications generally do a pretty good job of looking native on whatever operating system you are using without very much effort (even between Gnome/KDE on Linux). Qt also has excellent documentation, lots of sample code, a generous license and is well-maintained.

Answered By: Adam Batkin

From a python prompt try this.

import gtk

icon = gtk.StatusIcon()
icon.set_from_stock(gtk.STOCK_ABOUT)

gtk.main()

You should see an icon in the system tray.

See this snippet for a bigger example.

Answered By: Neil
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.