Skip to main content

Detect OS Dark Mode from Python

Project description

Darkdetect

This package allows to detect if the user is using Dark Mode on:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

darkdetect-0.7.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

darkdetect-0.7.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file darkdetect-0.7.0.tar.gz.

File metadata

  • Download URL: darkdetect-0.7.0.tar.gz
  • Upload date:
  • Size: 6.6 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

Hashes for darkdetect-0.7.0.tar.gz
Algorithm Hash digest
SHA256 13a15decfc828334a5e4041fd08d3a1f5b9717d5fce268b3dc614c10a06e43ce
MD5 33f58687a1b2d56f623fd9df421a3499
BLAKE2b-256 daee6195b409fda091ee5830035387f1e47d1e14a7520380cb14e5e7bf50cd75

See more details on using hashes here.

File details

Details for the file darkdetect-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: darkdetect-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: 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

Hashes for darkdetect-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f80a4e25ce289d6c808ae1c312e4b96fe9b975c315d94b3afe6244e186f7b22
MD5 b6262ac76226e30741b6e4f44ff5e8b1
BLAKE2b-256 ee3844d3fcb0fbf78d11b4b4ff4d6253c24a60f176b572c89b357b39b7c6eb67

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page