Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an application for the system tray in Linux

People also ask

How do I add apps to system tray Ubuntu?

Step 1: Launch the program you wish to keep in the Linux system tray and put it in focus by clicking on it with the mouse. This program must be the only program on the screen, or Kdocker may not work right. What is this? Step 2: Open up the app menu on your Linux desktop, and locate “Kdocker” in the app menu.

What is system tray in Linux?

The system tray is a notification area on the operating system taskbar. It contains icons that provide users with easy access to system functions such as email, printer, network connections and volume control. The icons also indicate the statuses of the processes running on the computer.

Does Linux have a system tray?

The system tray (or "systray") is a section of the taskbars in the Microsoft Windows operating system (OS) user interface that provides easy access icons to the user's most commonly used apps and displays the clock. A system tray is also available in other OSes such as Linux, Mac OS, Android and iOS.


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.


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


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.


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.