MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / make_window

Function make_window

DemoPrograms/Demo_User_Settings_Class.py:37–66  ·  view source on GitHub ↗

Creates a new window. The default values for some elements are pulled directly from the "User Settings" without the use of temp variables. Some get_entry calls don't have a default value, such as theme, because there was an initial call that would have set the default value if the

()

Source from the content-addressed store, hash-verified

35settings = sg.UserSettings(path=SETTINGS_PATH)
36
37def make_window():
38 """
39 Creates a new window. The default values for some elements are pulled directly from the
40 "User Settings" without the use of temp variables.
41
42 Some get_entry calls don't have a default value, such as theme, because there was an initial call
43 that would have set the default value if the setting wasn't present. Could still put the default
44 value if you wanted but it would be 2 places to change if you wanted a different default value.
45
46 Use of a lookup table to map between element keys and user settings could be aded. This demo
47 is intentionally done without one to show how to use the settings APIs in the most basic,
48 straightforward way.
49
50 If your application allows changing the theme, then a make_window function is good to have
51 so that you can close and re-create a window easily.
52
53 :return: (sg.Window) The window that was created
54 """
55
56 sg.theme(settings.get('-theme-', 'DarkBlue2')) # set the theme
57
58 layout = [[sg.Text('Settings Window')],
59 [sg.Input(settings.get('-input-', ''), k='-IN-')],
60 [sg.Listbox(sg.theme_list(), default_values=[settings['-theme-'],], size=(15, 10), k='-LISTBOX-')],
61 [sg.CB('Option 1', settings.get('-option1-', True), k='-CB1-')],
62 [sg.CB('Option 2', settings.get('-option2-', False), k='-CB2-')],
63 [sg.T('Settings file = ' + settings.get_filename())],
64 [sg.Button('Save'), sg.Button('Settings Dictionary'), sg.Button('Exit without saving', k='Exit')]]
65
66 window = sg.Window('A Settings Window', layout)
67
68
69def settings_window():

Callers 1

settings_windowFunction · 0.70

Calls 2

get_filenameMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected