[Python] How to get user current system theme color

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    hi I am working on a python gui project and I find that the color of the frame of my application depends on the user's system theme color. I want my application to have the same color, may I know how can I achieve that? My application is mainly for windows but if theres a way for linux that would be great. I am using tkinter btw.
    Or maybe how to get the color from commandline since we have os.system(command) ?

    Update: I have tried inputs listed in widget styling but none of them work, my system has a theme color of 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()


    Setting the background to black does not set the frame to black and I can't find a way to get the light blue color
    [​IMG]

    Continue reading...

Compartilhe esta Página