Detect OS Dark Mode from Python
Project description
Darkdetect
This package allows to detect if the user is using Dark Mode on:
- macOS 10.14+
- Windows 10 1607+
- Linux with a dark GTK theme.
The main application of this package is to detect the Dark mode from your GUI Python application (Tkinter/wx/pyqt/qt for python (pyside)/...) and apply the needed adjustments to your interface. Darkdetect is particularly useful if your GUI library does not provide a public API for this detection (I am looking at you, Qt). In addition, this package does not depend on other modules or packages that are not already included in standard Python distributions.
Usage
import darkdetect
>>> darkdetect.theme()
'Dark'
>>> darkdetect.isDark()
True
>>> darkdetect.isLight()
False
It's that easy.
You can create a dark mode switch listener daemon thread with darkdetect.listener
and pass a callback function. The function will be called with string "Dark" or "Light" when the OS switches the dark mode setting.
import threading
import darkdetect
# def listener(callback: typing.Callable[[str], None]) -> None: ...
t = threading.Thread(target=darkdetect.listener, args=(print,))
t.daemon = True
t.start()
On macOS it simply raises a NotImplementedError. PRs in this direction are more than welcome.
Install
The preferred channel is PyPI:
pip install darkdetect
Alternatively, you are free to vendor directly a copy of Darkdetect in your app. Further information on vendoring can be found here.
Notes
- This software is licensed under the terms of the 3-clause BSD License.
- This package can be installed on any operative system, but it will always return
None
unless executed on a OS that supports Dark Mode, including older versions of macOS and Windows. - On macOS, detection of the dark menu bar and dock option (available from macOS 10.10) is not supported.
- Details on the detection method used on macOS.
- Details on the experimental detection method used on Linux.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file darkdetect-0.7.1.tar.gz
.
File metadata
- Download URL: darkdetect-0.7.1.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47be3cf5134432ddb616bbffc927237718407914993c82809983e7ccebf49013 |
|
MD5 | d21ffe3b46c41ae9660f064cbd1b9495 |
|
BLAKE2b-256 | 482e346667de53b48417e6237efd9d076d6530c413666fcbc381adbfeff21ce7 |
File details
Details for the file darkdetect-0.7.1-py2.py3-none-any.whl
.
File metadata
- Download URL: darkdetect-0.7.1-py2.py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3efe69f8ecd5f1b7f4fbb0d1d93f656b0e493c45cc49222380ffe2a529cbc866 |
|
MD5 | 9ecef5c145fa041c2db78af6d004c207 |
|
BLAKE2b-256 | 63bdb31abc8fcaab163e0b9501020309dd9094b47d609035a23e6ec0a0a8ba10 |