MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / change_look_and_feel

Function change_look_and_feel

PySimpleGUI/PySimpleGUI.py:20059–20145  ·  view source on GitHub ↗

Change the "color scheme" of all future PySimpleGUI Windows. The scheme are string names that specify a group of colors. Background colors, text colors, button colors. There are 13 different color settings that are changed at one time using a single call to ChangeLookAndFeel The loo

(index, force=False)

Source from the content-addressed store, hash-verified

20057
20058
20059def change_look_and_feel(index, force=False):
20060 """
20061 Change the "color scheme" of all future PySimpleGUI Windows.
20062 The scheme are string names that specify a group of colors. Background colors, text colors, button colors.
20063 There are 13 different color settings that are changed at one time using a single call to ChangeLookAndFeel
20064 The look and feel table itself has these indexes into the dictionary LOOK_AND_FEEL_TABLE.
20065 The original list was (prior to a major rework and renaming)... these names still work...
20066 In Nov 2019 a new Theme Formula was devised to make choosing a theme easier:
20067 The "Formula" is:
20068 ["Dark" or "Light"] Color Number
20069 Colors can be Blue Brown Grey Green Purple Red Teal Yellow Black
20070 The number will vary for each pair. There are more DarkGrey entries than there are LightYellow for example.
20071 Default = The default settings (only button color is different than system default)
20072 Default1 = The full system default including the button (everything's gray... how sad... don't be all gray... please....)
20073 :param index: the name of the index into the Look and Feel table (does not have to be exact, can be "fuzzy")
20074 :type index: (str)
20075 :param force: no longer used
20076 :type force: (bool)
20077 :return: None
20078 :rtype: None
20079 """
20080 global CURRENT_LOOK_AND_FEEL
20081
20082 # if running_mac() and not force:
20083 # print('*** Changing look and feel is not supported on Mac platform ***')
20084 # return
20085
20086 requested_theme_name = index
20087 theme_names_list = list_of_look_and_feel_values()
20088 # normalize available l&f values by setting all to lower case
20089 lf_values_lowercase = [item.lower() for item in theme_names_list]
20090 # option 1
20091 opt1 = requested_theme_name.replace(' ', '').lower()
20092 # option 3 is option 1 with gray replaced with grey
20093 opt3 = opt1.replace('gray', 'grey')
20094 # option 2 (reverse lookup)
20095 optx = requested_theme_name.lower().split(' ')
20096 optx.reverse()
20097 opt2 = ''.join(optx)
20098
20099 # search for valid l&f name
20100 if requested_theme_name in theme_names_list:
20101 ix = theme_names_list.index(requested_theme_name)
20102 elif opt1 in lf_values_lowercase:
20103 ix = lf_values_lowercase.index(opt1)
20104 elif opt2 in lf_values_lowercase:
20105 ix = lf_values_lowercase.index(opt2)
20106 elif opt3 in lf_values_lowercase:
20107 ix = lf_values_lowercase.index(opt3)
20108 else:
20109 ix = random.randint(0, len(lf_values_lowercase) - 1)
20110 print('** Warning - {} Theme is not a valid theme. Change your theme call. **'.format(index))
20111 print('valid values are', list_of_look_and_feel_values())
20112 print('Instead, please enjoy a random Theme named {}'.format(list_of_look_and_feel_values()[ix]))
20113
20114 selection = theme_names_list[ix]
20115 CURRENT_LOOK_AND_FEEL = selection
20116 try:

Callers 1

themeFunction · 0.85

Calls 1

Tested by

no test coverage detected