28

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.

  • 6
    linux doesn't have a system tray - your window manager might - which one are you using? –  Jul 29 '09 at 22:38
  • 2
    Yeah sorry, I use Xmonad with xmobar. trayer as my system tray. But I'm not sure why it's relevant to my question? –  Jul 29 '09 at 22:46
  • 4
    (It's not relevant, not since the freedesktop spec. (which was the whole point of having it.)) – Anders Eurenius Jul 30 '09 at 21:06

4 Answers4

27

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.

pevik
  • 4,523
  • 3
  • 33
  • 44
Adam Batkin
  • 51,711
  • 9
  • 123
  • 115
9

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...)

Anders Eurenius
  • 4,170
  • 2
  • 24
  • 20
  • 1
    Note: currently not in debian (https://packages.debian.org/python-eggtrayicon, http://packages.qa.debian.org/gnome-python-extras). – pevik Feb 10 '16 at 10:49
5

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.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
Kaleb Pederson
  • 45,767
  • 19
  • 102
  • 147
3

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.

Neil
  • 8,925
  • 10
  • 44
  • 49