从python检测macos中的暗模式 [英] Detect dark mode in macos from python

查看:214
本文介绍了从python检测macos中的暗模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个PyQt应用程序,我必须添加一个补丁程序,以便在启用了暗模式的macOS上可读该字体:

I am writing a PyQt app and I have to add a patch so that the font is readable on macos with dark mode enabled:

app = QApplication([])
# Fix for the font colours on macos when running dark mode
if sys.platform == 'darwin':
    p = app.palette()
    p.setColor(QPalette.Base, QColor(101, 101, 101))
    p.setColor(QPalette.ButtonText, QColor(231, 231, 231))
    app.setPalette(p)
main_window = MainWindow()
main_window.show()
app.exec_()

此修补程序的问题在于,在光亮模式下,macOS无法读取内容.

The issue with this patch is then it makes things unreadable on macos with light mode.

是否可以通过python或通过子进程使用标准的shell命令在macOS上检测暗模式?

Is there a way I can detect dark mode on macos from python or using a standard shell command through subprocess?

从PyQt 5.12开始,不再需要暗模式修复.

As of PyQt 5.12 the dark mode fix is no longer required.

推荐答案

基于

Building on this question, you could install pyobjc and use NSUserDefaults:

>>> from Foundation import NSUserDefaults
>>> NSUserDefaults.standardUserDefaults().stringForKey_('AppleInterfaceStyle')
'Dark'

这篇关于从python检测macos中的暗模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆