🌐
PySimpleGUI
docs.pysimplegui.com › en › latest › documentation › module › themes
Themes - PySimpleGUI Documentation
In the PySimpleGUI System Settings, you can define a default theme that will be applied across all PySimpleGUI programs you make.
🌐
PySimpleGUI
docs.pysimplegui.com › en › latest › cookbook › original › adding_own_theme
Adding Your Own Color Theme - PySimpleGUI Documentation
To add the new theme to the standard themes this code will do it: import PySimpleGUI as sg # Add your new theme colors and settings my_new_theme = {'BACKGROUND': '#709053', 'TEXT': '#fff4c9', 'INPUT': '#c7e78b', 'TEXT_INPUT': '#000000', 'SCROLL': '#c7e78b', 'BUTTON': ('white', '#709053'), 'PROGRESS': ('#01826B', '#D0D0D0'), 'BORDER': 1, 'SLIDER_DEPTH': 0, 'PROGRESS_DEPTH': 0} # Add your dictionary to the PySimpleGUI themes sg.theme_add_new('MyNewTheme', my_new_theme) # Switch your theme to use the newly added one.
Discussions

Change theme dynamically on the fly
Type of Issues (Enhancement, Error, Bug, Question): Enhancement Operating System: windows Python version: 3.6 PySimpleGUI Port and Version: tkinter Hello Mike, This is not an urgent request, I know you are busy so you can delay it when y... More on github.com
🌐 github.com
40
December 26, 2019
python - PySimpleGUI theme updates? - Stack Overflow
I am new to Python and PySimpleGUI. I'm just playing around at the moment with the Everything Bagel sample program available from the PySImpleGUI website. I have got the second window to work for More on stackoverflow.com
🌐 stackoverflow.com
September 24, 2020
python - Themes not showing up in PySimpleGUI - Stack Overflow
There's this problem for me in PySimpleGUI where it doesn't show me the theme I want. I tried several themes and it presented me with dark mode. Can anyone help? import PySimpleGUI as sg def More on stackoverflow.com
🌐 stackoverflow.com
python - How do I change background color in pysimplegui? - Stack Overflow
I took most of the code from the one of the demo projects because i couldn't figure out how to implement matplotlib with pysimplegui so there's some things I don't fully understand but usually with pysimplegui it's as simple as sg.theme="color to change the main background color but it isn't ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/python › color themes - pysimplegui adds significantly more - over 100 choices now
r/Python on Reddit: Color Themes - PySimpleGUI Adds Significantly More - Over 100 Choices Now
November 17, 2019 -

The idea of using "Look and Feel" settings goes way back with PySimpleGUI. You may have seen the green and tan colors windows from time to time. It's a feature that wasn't put into very many of the demo programs.

Because the demos are often the starting point for projects, it made sense to begin to spice things up a little and add color right from the start. Not everyone will be pleased with the color selection. You can always remove the call entirely (it's 1 line of code), or choose another one. Point is they are coming to a screen near you.

Previously you needed to specify the exact name of the Theme. Now it's a "Fuzzy" match. "Grey Dark 2" or "DarkGray2" both work. The original 28 Themes are sill available using the old names. They are also available using a new naming convention. The new convention is:

<"Dark" | "Light"> <Color> [#]

Where color can be: Black, Blue, Green, Teal, Brown, Yellow, Grey, Purple

Not all combinations are represented and now every combination has the same number of choices as others. For example there are 9 Dark Blue themes and 1 Light Yellow.

You can get a text list of the choices by calling:

import PySimpleGUI as sg
sg.list_of_look_and_feel_values()

You will also get this text list on your console if you pass in a value that doesn't match a valid Theme.

You can also get a visual dump of the choices by calling:

sg.preview_all_look_and_feel_themes()

With the straight PySimpleGUI port (tkinter), the preview looks like this:

You can use these on the Qt and Web ports as well. The same values work and you can also make the same preview call. for the PySimpleGUIWeb port, the preview looks like this:

Putting these color themes to use is as simple as adding this line of code to your program, any place prior to creating your layout or calling a popup:

sg.change_look_and_feel('Theme Name Here') 

Note that this possibly a first step in creating a nice looking window. It is merely settings up some colors for you. There is more you can do to polish your window should you wish. The idea here is for people to take a break from creating and looking at gray windows all the time, especially when starting out.

If your program only has popup calls, that's OK, changing the Look and Feel changes the colors for all future windows (until another change is made).

If you have additional color scheme ideas, there is a defined format so that you can add your own by adding a dictionary entry into the Theme table.

🌐
GeeksforGeeks
geeksforgeeks.org › python › themes-in-pysimplegui
Themes in PySimpleGUI - GeeksforGeeks
June 3, 2024 - # import PySimpleGUI import PySimpleGUI as sg # Choose a Theme for the Layout sg.theme('DarkTeal9') layout = [[sg.Text('List of InBuilt Themes')], [sg.Text('Please Choose a Theme to see Demo window')], [sg.Listbox(values = sg.theme_list(), size =(20, 12), key ='-LIST-', enable_events = True)], [sg.Button('Exit')]] window = sg.Window('Theme List', layout) # This is an Event Loop while True: event, values = window.read() if event in (None, 'Exit'): break sg.theme(values['-LIST-'][0]) sg.popup_get_text('This is {}'.format(values['-LIST-'][0])) # Close window.close()
🌐
PySimpleGUI
docs.pysimplegui.com › en › latest › cookbook › original › theme_modification
Modifying an existing Theme - PySimpleGUI Documentation
Passing in the color 'blue' as the parameter, theme_background_color('blue'), will change the background color for future windows you create to blue. import PySimpleGUI as sg sg.theme('LightGreen3') sg.popup_no_wait('This is the standard LightGreen3 Theme', 'It has white button text') # Modify the theme sg.theme_button(('black', '#6D9F85')) sg.popup('This is the modified LightGreen3 Theme', 'It has black button text')
🌐
PySimpleGUI
docs.pysimplegui.com › en › latest › cookbook › original › theme_viewer
Built-in Theme Viewer - PySimpleGUI Documentation
If you want to see a window on your system like the above theme preview screenshot, then make this call and you'll see the same window: import PySimpleGUI as sg sg.preview_all_look_and_feel_themes()
🌐
GitHub
github.com › PySimpleGUI › PySimpleGUI › issues › 2437
Change theme dynamically on the fly · Issue #2437 · PySimpleGUI/PySimpleGUI
December 26, 2019 - below is an example, where you can select theme and it will iterate over all window elements and change colors according to the selected theme, however it doesn't work as expected the window background doesn't fill completely around other elements, i think i am missing something, please have a look, as you are the expert here who can come up with an acceptable implementation · import PySimpleGUI as sg themes = sg.ListOfLookAndFeelValues() selected_theme = 'Reds' current_them = sg.LOOK_AND_FEEL_TABLE[selected_theme] sg.ChangeLookAndFeel(selected_theme) layout = [ [sg.T('User Setting:')], [sg.T
Author   firedm
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 64047768 › pysimplegui-theme-updates
python - PySimpleGUI theme updates? - Stack Overflow
September 24, 2020 - #!/usr/bin/env Python3 import PySimpleGUI as sg import time sg.ChangeLookAndFeel('GreenTan') def theme_browser_window_1(new_theme_1): layout_1 = [[sg.Text('Theme Browser')], [sg.Text('Click a Theme color to see demo window')], [sg.Listbox(values=sg.theme_list(), size=(20, 12), key='-LIST-', enable_events=True)], [sg.Button('Exit')]] #layout_tb = "" #layout_tb = layout_1 window_1 = sg.Window('Theme Browser', layout_1) while True: # Event Loop event, values = window_1.read() if event == sg.WIN_CLOSED or event == 'Exit': break sg.theme(values['-LIST-'][0]) sg.popup_get_text('This is {}'.format(va
🌐
GitHub
github.com › definite-d › Themera
GitHub - definite-d/Themera: PySimpleGUI theme code generator.
It enables you to create themes based on any of the existing themes that comes built in with PySimpleGUI, edit any custom existing theme based on the dictionary containing its colors, or create a theme from an image.
Starred by 29 users
Forked by 9 users
Languages   Python 99.4% | Inno Setup 0.6% | Python 99.4% | Inno Setup 0.6%
🌐
Readthedocs
freesimplegui.readthedocs.io › en › stable
PySimpleGUI - FreeSimpleGUI - Read the Docs
Once upon a time there was a package called PySimpleGUI that people liked a lot. The owners decided to rug-pull its continued availability and re-license it with a proprietary commercial license under a paid subscription. FreeSimpleGUI is the continuation of the LGPL3 licensed version last available. FreeSimpleGUI will remain free and permissively licensed forever. New APIs to save you time - not just for beginners ... System-wide global settings - theme, interpreter to use, Mac settings, ...
🌐
GitHub
github.com › PySimpleGUI › PySimpleGUI › blob › master › DemoPrograms › Demo_Theme_Color_Swatches.py
PySimpleGUI/DemoPrograms/Demo_Theme_Color_Swatches.py at master · PySimpleGUI/PySimpleGUI
You may not redistribute, modify or otherwise use PySimpleGUI or its contents except pursuant to the PySimpleGUI License Agreement. ... layout = [[sg.Text('Themes as color swatches', text_color='white', background_color='black', font='Default 25')],
Author   PySimpleGUI
🌐
Readthedocs
freesimplegui.readthedocs.io › en › latest › cookbook
The PySimpleGUI Cookbook - FreeSimpleGUI
import FreeSimpleGUI as sg # Add your new theme colors and settings my_new_theme = {'BACKGROUND': '#709053', 'TEXT': '#fff4c9', 'INPUT': '#c7e78b', 'TEXT_INPUT': '#000000', 'SCROLL': '#c7e78b', 'BUTTON': ('white', '#709053'), 'PROGRESS': ('#01826B', '#D0D0D0'), 'BORDER': 1, 'SLIDER_DEPTH': 0, 'PROGRESS_DEPTH': 0} # Add your dictionary to the PySimpleGUI themes sg.theme_add_new('MyNewTheme', my_new_theme) # Switch your theme to use the newly added one.
Top answer
1 of 3
4

You can change the background color by specifying a Hex Color Code in the following argument under layout:

background_color='#DAE0E6'

You can use a Color Picker like this one https://htmlcolorcodes.com/color-picker/ to get your color

You can also use:

window = sg.Window('Virus Simulation', layout, background_color='hex_color_code')

To change the color of a window object

2 of 3
1

I'm a tad confused in 2 ways.

1 - I don't see a call to sg.theme() in your code, so I don't know where it was in the code. WHERE it is placed matters. Always place the theme as early as possible, definitely before making your layout. 2 - I don't know what "it isn't working this time means". Again, it's more of needing to see a complete example to get it.

The sample code in the question that you said normally works was weirdly formatted so something must have been scrambled.

The question shows: sg.theme="color

But as Jason has pointed out, the value passed to sg.theme() is more than a color. The "Theme Name Formula" is described in the main PySimpleGUI documentation here - https://pysimplegui.readthedocs.io/en/latest/#theme-name-formula. In case there's a problem getting to that section, here's what it says:

Theme Name Formula
Themes names that you specify can be "fuzzy". The text does not have to match exactly what you see printed. For example "Dark Blue 3" and "DarkBlue3" and "dark blue 3" all work.

One way to quickly determine the best setting for your window is to simply display your window using a lot of different themes. Add the line of code to set the theme - theme('Dark Green 1'), run your code, see if you like it, if not, change the theme string to 'Dark Green 2' and try again. Repeat until you find something you like.

The "Formula" for the string is:

Dark Color #

or

Light Color #

Color can be Blue, Green, Black, Gray, Purple, Brown, Teal, Red. The # is optional or can be from 1 to XX. Some colors have a lot of choices. There are 13 "Light Brown" choices for example.

If you want to only change the background color of your theme, then you can use individual color names or hex values. sg.theme_background_color('#FF0000') or sg.theme_background_color('red') will set the background color to red.

Hope that helps with themes.


Nice work on using the PSG coding conventions. Looking at your code was effortless as a result. Zero guesswork as to what I was seeing. Great to see and it helps in numerous ways when you use them.

Top answer
1 of 2
1

A new demo was posted showing how to do this on tie PySimpleGUI GitHub. Look for Demo_Theme_Change_Your_Windows_Theme.py

Here's the source from it:

import PySimpleGUI as sg

"""
    Demo - Changing your window's theme at runtime
    * Create your window using a "window create function"
    * When your window's theme changes, close the window, call the "window create function"
    
    Copyright 2021 PySimpleGUI
"""

# ------------------- Create the window -------------------
def make_window(theme=None):
    if theme:
        sg.theme(theme)
    # -----  Layout & Window Create  -----
    layout = [[sg.T('This is your layout')],
              [sg.Button('Ok'), sg.Button('Change Theme'), sg.Button('Exit')]]

    return sg.Window('Pattern for changing theme', layout)


# ------------------- Main Program and Event Loop -------------------
def main():
    window = make_window()

    while True:
        event, values = window.read()
        if event == sg.WINDOW_CLOSED or event == 'Exit':
            break
        if event == 'Change Theme':      # Theme button clicked, so get new theme and restart window
            event, values = sg.Window('Choose Theme',
                                      [[sg.Combo(sg.theme_list(), readonly=True, k='-THEME LIST-'), sg.OK(), sg.Cancel()]]
                                      ).read(close=True)
            if event == 'OK':
                # ---- Switch to your new theme! ---- IMPORTANT PART OF THE PROGRA<
                window.close()
                window = make_window(values['-THEME LIST-'])

    window.close()


if __name__ == '__main__':
    main()
2 of 2
1

An example that allows you to select a new theme from a theme browser showing all themes -no combo selection is needed- and updates a window by closing and recreating it.

Here is the source code:

import PySimpleGUI as sg

selected_theme = 'LightGreen'
sg.theme(selected_theme)

theme_list = sg.theme_list()
theme_list.sort()

NUM_COLUMNS = 8
theme_list_size = len(theme_list)
num_rows = int(theme_list_size/NUM_COLUMNS)


def create_theme_box(theme_index):  
    sg.theme(theme_list[theme_index])
    return sg.Column(
        [
            [sg.Text('' + theme_list[theme_index], size=(16,1))] +
            [sg.Button('Select', k=str(theme_index)),] ,
        ]
    )


def create_theme_example(theme):
    sg.theme(theme)
    theme_frame = [
        [sg.Checkbox('Checkbox')] +
                [sg.Slider(range=(0, 100), orientation='horizontal', size=(20, None), default_value=50)] +
                [sg.Button('Button')] +
                [sg.Text('     InputText:'), sg.InputText()],
    ]
    
    theme_example_layout = [
            [sg.Frame(selected_theme, theme_frame)],
        ]

    return sg.Window('Theme Example', theme_example_layout, resizable=True, finalize=True, location=(100,50))


theme_browser_layout = [
    [
        [create_theme_box(column+NUM_COLUMNS*row) for column in range(0, NUM_COLUMNS)] for row in range(0, num_rows)
    ],
    [
        create_theme_box(column + int(theme_list_size/NUM_COLUMNS)*NUM_COLUMNS) for column in range(0, (theme_list_size%NUM_COLUMNS))
    ],
]

def main():
    global selected_theme
   
    window_theme_browser = sg.Window('Theme Browser', theme_browser_layout, resizable=True, finalize=True, location=(100,200))
    window = create_theme_example(selected_theme)
    
    while True:
        event, values = window_theme_browser.read()
        if event == sg.WINDOW_CLOSED or event == 'Exit':
            break

        window.close()
        selected_theme = theme_list[int(event)]
        print("Selected:",selected_theme )

        window = create_theme_example(selected_theme)   

    window_theme_browser.close()
    window.close()


if __name__ == '__main__':
    main()

If you don't want to close and create the window but just update it with a new theme, and don't mind if it is portable or not, you can do it using tkinter. An example can be found in this thread: https://github.com/PySimpleGUI/PySimpleGUI/issues/2437

🌐
PySimpleGUI
docs.pysimplegui.com › en › latest › documentation › module › global_settings
Global Settings - PySimpleGUI Documentation
You can access the Global PySimpleGUI Settings Window in 3 ways: ... The settings window has 7 tabs and a separate window for Mac-specific settings. The Theme tab sets the theme for all of your PySimpleGUI program globally.
🌐
GitHub
github.com › PySimpleGUI › PySimpleGUI › blob › master › DemoPrograms › Demo_Look_And_Feel_Theme_Dump.py
PySimpleGUI/DemoPrograms/Demo_Look_And_Feel_Theme_Dump.py at master · PySimpleGUI/PySimpleGUI
You may not redistribute, modify or otherwise use PySimpleGUI or its contents except pursuant to the PySimpleGUI License Agreement. ... # own custom theme viewer window. You can configure the number of frames per row for example.
Author   PySimpleGUI