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

Function make_window

DemoPrograms/Demo_Desktop_Widget_Count_To_A_Goal.py:295–346  ·  view source on GitHub ↗
(location, test_window=False)

Source from the content-addressed store, hash-verified

293 return None
294
295def make_window(location, test_window=False):
296 title_font = sg.user_settings_get_entry('-title font-', 'Courier 8')
297 title = sg.user_settings_get_entry('-title-', '')
298 main_number_font = sg.user_settings_get_entry('-main number font-', 'Courier 70')
299
300 if not test_window:
301 theme = sg.user_settings_get_entry('-theme-', THEME)
302 sg.theme(theme)
303
304 alpha = sg.user_settings_get_entry('-alpha-', ALPHA)
305
306 # ------------------- Window Layout -------------------
307 # If this is a test window (for choosing theme), then uses some extra Text Elements to display theme info
308 # and also enables events for the elements to make the window easy to close
309 if test_window:
310 top_elements = [[sg.Text(title, size=(20, 1), font=title_font, justification='c', k='-TITLE-', enable_events=True)],
311 [sg.Text('Click to close', font=title_font, enable_events=True)],
312 [sg.Text('This is theme', font=title_font, enable_events=True)],
313 [sg.Text(sg.theme(), font=title_font, enable_events=True)]]
314 right_click_menu = [[''], ['Exit',]]
315 else:
316 top_elements = [[sg.Text(title, size=(20, 1), font=title_font, justification='c', k='-TITLE-')]]
317 right_click_menu = [[''], ['Set Count','Set Goal','Choose Title', 'Edit Me', 'Change Theme', 'Save Location', 'Refresh', 'Set Title Font', 'Set Main Font','Alpha', [str(x) for x in range(1, 11)], 'Exit', ]]
318
319 gsize = (100, 55)
320
321
322 layout = top_elements + \
323 [[sg.Text('0', size=main_info_size, font=main_number_font, k='-MAIN INFO-', justification='c', enable_events=test_window)],
324 sg.vbottom([sg.Text(0, size=(3, 1), justification='r', font='courier 20'),
325 sg.Graph(gsize, (-gsize[0] // 2, 0), (gsize[0] // 2, gsize[1]), key='-Graph-'),
326 sg.Text(0, size=(3, 1), font='courier 20', k='-GOAL-')]),
327 ]
328
329
330
331 try:
332 window = sg.Window('Counter Widget', layout, location=location, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_justification='c', element_padding=(0, 0), alpha_channel=alpha, finalize=True, right_click_menu=right_click_menu, right_click_menu_tearoff=False, keep_on_top=True)
333 except Exception as e:
334 if sg.popup_yes_no('Error creating your window', e, 'These are your current settings:', sg.user_settings(), 'Do you want to delete your settings file?') == 'Yes':
335 sg.user_settings_delete_filename()
336 sg.popup('Settings deleted.','Please restart your program')
337 exit()
338 window = None
339
340 window.gauge = Gauge(pointer_color=sg.theme_text_color(), clock_color=sg.theme_text_color(), major_tick_color=sg.theme_text_color(),
341 minor_tick_color=sg.theme_input_background_color(), pointer_outer_color=sg.theme_text_color(), major_tick_start_radius=45,
342 minor_tick_start_radius=45, minor_tick_stop_radius=50, major_tick_stop_radius=50, major_tick_step=30, clock_radius=50, pointer_line_width=3, pointer_inner_radius=10, pointer_outer_radius=50, graph_elem=window['-Graph-'])
343
344 window.gauge.change(degree=0)
345
346 return window
347
348def main():
349 loc = sg.user_settings_get_entry('-location-', (None, None))

Callers 2

choose_themeFunction · 0.70
mainFunction · 0.70

Calls 2

GaugeClass · 0.70
changeMethod · 0.45

Tested by

no test coverage detected