

With those two code snippets, you can create a Python application that helps you change the display resolution from the Windows system tray: Changing the Windows Display Resolution from the System Tray / Taskbar When the Quit menu item is clicked, the on_quit() function is called and ends the Python application. And in the last two lines, the system tray is created and started using n(). Next, in lines 12 to 16 a menu for the system tray icon is created using item objects with call-back to the function executed when the menu item was clicked on. run ()įirst, the Python code needs an image file (256x256 px) as an icon for the system tray in line 10.

Icon ( "name", image, "title", menu ) icon. open ( "icon.png" ) menu = ( item ( 'MenuItem0', None ), item ( 'MenuItem1', None ), item ( 'Quit', on_quit ) ) icon = pystray. Import pystray from PIL import Image from pystray import MenuItem as item def on_quit (): icon. Installing it can also be done using pip: Adding a Python application to the system tray is pretty straightforward using the package pystray that provides an operating agnostic API to add a Python application to the system tray. Therefore we want to add this Python application to the Windows system tray to be easily accessed via a right-click. Manually running the code above is only slightly better or even worse than using the Windows display settings to change the resolution. Adding a Python Application to the Windows 10/11 System Tray Make sure to pick a resolution your monitor supports before running the script otherwise, nothing happens.

In lines 6 and 7 the new display resolution is set using devmode.PelsWidth and devmode.PelsHeight for the width and height in pixels. Import pywintypes import win32api import win32con devmode = pywintypes.
