Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a SystemTray app for Windows?

I usually work on a Linux system, but I have a situation where I need to write a client app that would run on windows as a service. Can someone help me or direct, on how to build a system tray app (for example like dropbox) for the windows environment, which gets started on OS startup and the icon sits in the TaskBar and on clicking the app icon presents a menu.

My scripting language is python. Thanks.

like image 805
Zakiullah Khan Avatar asked Feb 29 '12 06:02

Zakiullah Khan


People also ask

How do I create a system tray in Windows 10?

Step 1 − Go to the SETTINGS window and choose System. Step 2 − In the SYSTEM window, select Notifications & actions. Here you can select the option that reads “Select which icons appear on the taskbar”.

How do I add apps to Windows system tray?

Select Start , select the arrow next to All apps, right-click the app, then select More > Pin to taskbar. If the app is already open on the desktop, press and hold (or right click) the app's taskbar icon, and then select Pin to taskbar.

How do I create a system tray application in Python?

To create a System Tray icon of a tkinter application, we can use pystray module in Python. It has many inbuilt functions and methods that can be used to configure the system tray icon of the application. To install pystray in your machine, you can type "pip install pystray" command in your shell or command prompt.


2 Answers

You do this using the pywin32 (Python for Windows Extensions) module.

Example Code for Python 2

Similar Question

To make it run at startup you could mess around with services but it's actually much easier to install a link to the exe in the users "Startup Folder".

Windows 7 and Vista

c:\Users\[username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Windows XP

c:\Documents and Settings\[username]\Start Menu\Programs\Startup

like image 122
SpliFF Avatar answered Sep 19 '22 18:09

SpliFF


There are (at least) a couple of libraries openly available for this now:

  • pystray
  • infi.systray

I just started using infi.systray in a project, and it's worked well for me. Here's how little code you need to do something very basic (taken from their docs):

from infi.systray import SysTrayIcon def say_hello(systray):     print("Hello, World!") menu_options = (("Say Hello", None, say_hello),) systray = SysTrayIcon("icon.ico", "Example tray icon", menu_options) systray.start() 
like image 37
Nathan Avatar answered Sep 23 '22 18:09

Nathan