如何获取用户当前的系统信息

2024-04-16 10:37:47 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我正在做一个pythongui项目,我发现我的应用程序框架的颜色取决于用户的系统主题颜色。我希望我的应用程序有相同的颜色,我可以知道我如何才能做到这一点?我的应用程序主要是针对windows的,但是如果有一种适合linux的方法那就太好了。我正在使用tkinter btw.
或者我们有了os.system(command),如何从命令行获取颜色?

更新: 我尝试了widget styling中列出的输入,但是没有一个有效,我的系统的主题颜色是light blue

from tkinter import *

if __name__ == '__main__':
    root = Tk()
    root['bg'] = 'SystemButtonFace'  # white
    root['bg'] = 'SystemBackground'  # black
    root['bg'] = 'SystemButtonText'  # black
    root['bg'] = 'SystemAppWorkspace'  # grey
    root['bg'] = 'SystemActiveBorder'  # grey
    root['bg'] = 'SystemActiveCaption'  # light grey
    root['bg'] = 'SystemInactiveCaption'  # light grey
    root['bg'] = 'SystemButtonShadow'  # darker grey
    root['bg'] = 'SystemButtonHighlight'  # white with a bit grey
    root['bg'] = 'SystemCaptionText'  # black
    root['bg'] = 'SystemDisabledText'  # darker grey
    root['bg'] = 'SystemHighlight'  # light dark blue
    root['bg'] = 'SystemHighlightText'  # white
    root['bg'] = 'SystemInactiveBorder'  # white
    root['bg'] = 'SystemInactiveCaptionText'  # black
    root['bg'] = 'SystemMenu'  # white
    root['bg'] = 'SystemMenuText'  # black
    root['bg'] = 'SystemScrollbar'  # grey
    root['bg'] = 'SystemWindow'  # white
    root['bg'] = 'SystemWindowFrame'  # dark grey
    root['bg'] = 'SystemWindowText'  # black

    root.mainloop()

将背景设置为黑色不会将框架设置为黑色,我也找不到获得浅蓝色的方法
info


Tags: 方法框架应用程序主题颜色tkinter系统blue
2条回答

您必须自己使用自定义的RGB颜色。你知道吗

使用'bg'键了解背景色。你知道吗

无论如何,如果要实现Tkinter框架的自定义,可以执行以下操作:

from tkinter import *

root = Tk()

print(root['bg']) # Output: SystemButtonFace
root.configure(bg = '#FF0000') # Configuring new color RED
print(root['bg']) # Output: #FF0000

root.mainloop()

有关tkinter样式的更多信息,请参见本页:

Widget Styling

查看Macintosh和Windows的默认系统颜色的段落。你知道吗

Linux可能没有系统颜色,因为它通常由黑色命令行管理。你知道吗

Tkinter无法更改窗口边框的颜色,也无法获取颜色。您需要使用其他特定于窗口管理器的库来获取或更改颜色。你知道吗

相关问题 更多 >