29

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.

3
  • 6
    linux doesn't have a system tray - your window manager might - which one are you using? Commented Jul 29, 2009 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? Commented Jul 29, 2009 at 22:46
  • 4
    (It's not relevant, not since the freedesktop spec. (which was the whole point of having it.)) Commented Jul 30, 2009 at 21:06

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

8

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

1 Comment

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.

2 Comments

the url provided has rotten :( please paste actual code/text from it.
I've updated the links for now. I'll try to put together a concise example later.
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.