System Tray Icons Not Showing or Not Closing on Windows

Troubleshooting common issues with QSystemTrayIcon on Windows 10 and 11
Heads up! You've already completed this tutorial.

I'm following a system tray tutorial on Windows 10. When I run the example code, nothing happens — no icon shows up in the system tray, and I have to force the program to stop. Even when the icon does appear, quitting from the menu doesn't fully close the app — the icon lingers and I have to use Task Manager. Other examples from the web have the same problem. What's going on?

This is a surprisingly common issue, and there are a few different things that can cause it. The good news is that most of them are straightforward to fix once you know what to look for. Let's walk through the main causes and solutions.

The icon file is missing or in the wrong place

The most common reason a system tray icon doesn't appear at all on Windows is that the icon file can't be found. Unlike on some other platforms, Windows will silently show nothing if the icon path is wrong — no error, no placeholder, just an empty system tray.

If your code looks something like this:

python
tray = QSystemTrayIcon(QIcon("icon.png"))
tray.show()

Then icon.png must be in the same directory you're running the script from. That's the current working directory, which might not be the same as the folder your script lives in — especially if you're running from an IDE.

You can make the path more reliable by building it relative to the script file:

python
import os

basedir = os.path.dirname(__file__)
icon_path = os.path.join(basedir, "icon.png")
tray = QSystemTrayIcon(QIcon(icon_path))

Or, to avoid the icon-file problem entirely while you're testing, you can use one of Qt's built-in standard icons:

python
style = app.style()
icon = QIcon(style.standardIcon(QStyle.StandardPixmap.SP_ComputerIcon))
tray = QSystemTrayIcon(icon)

This guarantees you'll see something in the tray, which helps you confirm the rest of your code is working.

Windows hides new tray icons

Windows 10 and 11 sometimes hide system tray icons automatically. Your app might actually be running, but the icon is tucked away in the overflow area. Click the small upward arrow (^) on the taskbar to expand the hidden icons and check if your icon is there.

You can change this behavior in Windows Settings under Taskbar > Other system tray icons (Windows 11) or Taskbar settings > Select which icons appear on the taskbar (Windows 10).

IDEs can interfere with the event loop

This is the issue that causes the most confusion. If you're running your system tray app from inside an IDE like Spyder, Jupyter Notebook, or even PyCharm in certain configurations, the app may not shut down cleanly when you call app.quit(). The icon can linger in the tray, the process can hang, and you end up reaching for Task Manager.

Why does this happen? IDEs often run your Python code inside their own process or kernel. When your Qt application calls app.quit(), it stops the Qt event loop — but the IDE's surrounding process keeps running. The operating system sees the process is still alive, so it keeps the tray icon around.

The simplest way to confirm whether this is an IDE issue is to run your script from the command line:

python
python systray.py

If the app starts, shows the icon, and quits cleanly from the command line, then the problem is with your IDE, not your code.

Working around IDE issues

Here are a few approaches:

  • Run from the terminal. This is the most reliable option for testing system tray apps. Save your script to a .py file and run it with python yourscript.py.
  • Use PyCharm with a clean virtual environment. PyCharm's run configurations tend to behave more predictably than Spyder or Jupyter for GUI applications. Create a virtual environment, install PyQt6 (or PySide6), and run from there.
  • Avoid Jupyter Notebook for GUI apps. Jupyter runs code in a kernel that doesn't play well with Qt's event loop. It's a great tool for data exploration, but GUI application development is better done elsewhere.

Make sure you have a proper quit action

A system tray application has no main window by default, so there's no "X" button to close it. You need to provide a way for the user to quit — typically through the right-click context menu. Without this, the only way to stop the app is to kill the process.

Here's how to add a quit action to the context menu:

python
quit_action = QAction("Quit")
quit_action.triggered.connect(app.quit)
menu.addAction(quit_action)

Also, because there's no main window, you need to tell Qt not to quit when the last window is closed (since there was never a window to begin with):

python
app.setQuitOnLastWindowClosed(False)

Without this line, the application might exit immediately on some platforms, or behave unpredictably.

Remember to right-click

This catches people out more often than you'd expect. On Windows, system tray icons respond to right-click, not left-click. Right-clicking opens the context menu where your actions (like "Quit") live. Left-clicking a tray icon can trigger an "activated" signal, but only if you've connected something to it.

Complete working example

Here's a full, self-contained system tray application for PyQt6 that uses a built-in icon so you don't need any image files. You can copy this, save it as systray.py, and run it from the command line:

python
import sys

from PyQt6.QtGui import QAction, QIcon
from PyQt6.QtWidgets import (
    QApplication,
    QMenu,
    QStyle,
    QSystemTrayIcon,
)

app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False)

# Use a built-in icon so we don't need an image file.
style = app.style()
icon = QIcon(style.standardIcon(QStyle.StandardPixmap.SP_ComputerIcon))

# Create the system tray icon.
tray = QSystemTrayIcon()
tray.setIcon(icon)
tray.setToolTip("My Tray App")

# Build the right-click context menu.
menu = QMenu()

action_hello = QAction("Say Hello")
action_hello.triggered.connect(lambda: print("Hello from the system tray!"))
menu.addAction(action_hello)

menu.addSeparator()

action_quit = QAction("Quit")
action_quit.triggered.connect(app.quit)
menu.addAction(action_quit)

tray.setContextMenu(menu)

# Show the tray icon.
tray.setVisible(True)

sys.exit(app.exec())

Run it with:

sh
$ python systray.py

You should see an icon appear in your system tray. Right-click it to see the menu. Choose "Say Hello" to print a message to the terminal, or "Quit" to close the app cleanly.

And here's the same example for PySide6:

python
import sys

from PySide6.QtGui import QAction, QIcon
from PySide6.QtWidgets import (
    QApplication,
    QMenu,
    QStyle,
    QSystemTrayIcon,
)

app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False)

# Use a built-in icon so we don't need an image file.
style = app.style()
icon = QIcon(style.standardIcon(QStyle.StandardPixmap.SP_ComputerIcon))

# Create the system tray icon.
tray = QSystemTrayIcon()
tray.setIcon(icon)
tray.setToolTip("My Tray App")

# Build the right-click context menu.
menu = QMenu()

action_hello = QAction("Say Hello")
action_hello.triggered.connect(lambda: print("Hello from the system tray!"))
menu.addAction(action_hello)

menu.addSeparator()

action_quit = QAction("Quit")
action_quit.triggered.connect(app.quit)
menu.addAction(action_quit)

tray.setContextMenu(menu)

# Show the tray icon.
tray.setVisible(True)

sys.exit(app.exec())
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

Packaging Python Applications with PyInstaller by Martin Fitzpatrick

This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book

Martin Fitzpatrick

System Tray Icons Not Showing or Not Closing on Windows was written by Martin Fitzpatrick.

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular Python books on the subject.