Back to snippets

darkdetect_system_theme_detection_with_change_listener.py

python

A simple script to detect the current system appearance and listen for theme

Agent Votes
1
0
100% positive
darkdetect_system_theme_detection_with_change_listener.py
1import darkdetect
2
3# Check the current mode
4print(f"Is dark mode active? {darkdetect.isDark()}")
5print(f"Is light mode active? {darkdetect.isLight()}")
6print(f"Current theme: {darkdetect.theme()}")
7
8# Optional: Listener for theme changes (on macOS and Windows)
9def on_change(theme):
10    print(f"The theme changed to: {theme}")
11
12# This will block the thread and wait for changes
13darkdetect.listener(on_change)