MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / choose_theme

Function choose_theme

DemoPrograms/Demo_Desktop_Widget_Date.py:26–64  ·  view source on GitHub ↗

A window to allow new themes to be tried out. Changes the theme to the newly chosen one and returns theme's name Automaticallyi switches to new theme and saves the setting in user settings file :param location: (x,y) location of the Widget's window :type location: Tuple[int, i

(location, size)

Source from the content-addressed store, hash-verified

24
25
26def choose_theme(location, size):
27 """
28 A window to allow new themes to be tried out.
29 Changes the theme to the newly chosen one and returns theme's name
30 Automaticallyi switches to new theme and saves the setting in user settings file
31
32 :param location: (x,y) location of the Widget's window
33 :type location: Tuple[int, int]
34 :param size: Size in pixels of the Widget's window
35 :type size: Tuple[int, int]
36 :return: The name of the newly selected theme
37 :rtype: None | str
38 """
39 layout = [[sg.Text('Try a theme')],
40 [sg.Listbox(values=sg.theme_list(), size=(20, 20), key='-LIST-', enable_events=True)],
41 [sg.OK(), sg.Cancel()]]
42
43 window = sg.Window('Look and Feel Browser', layout, location=location)
44 old_theme = sg.theme()
45 while True: # Event Loop
46 event, values = window.read()
47 if event in (sg.WIN_CLOSED, 'Exit', 'OK', 'Cancel'):
48 break
49 sg.theme(values['-LIST-'][0])
50 window.hide()
51 # make at test window to the left of the current one
52 test_window = make_window(location=((location[0] - size[0] * 1.2, location[1])), test_window=True)
53 test_window.read(close=True)
54 window.un_hide()
55 window.close()
56
57 # after choice made, save theme or restore the old one
58 if event == 'OK' and values['-LIST-']:
59 sg.theme(values['-LIST-'][0])
60 sg.user_settings_set_entry('-theme-', values['-LIST-'][0])
61 return values['-LIST-'][0]
62 else:
63 sg.theme(old_theme)
64 return None
65
66
67def make_window(location, test_window=False):

Callers 1

mainFunction · 0.70

Calls 5

readMethod · 0.95
hideMethod · 0.95
un_hideMethod · 0.95
closeMethod · 0.95
make_windowFunction · 0.70

Tested by

no test coverage detected