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

Function main

DemoPrograms/Demo_Desktop_Widget_Count_To_A_Goal.py:348–428  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

346 return window
347
348def main():
349 loc = sg.user_settings_get_entry('-location-', (None, None))
350 window = make_window(loc)
351 try:
352 current_count = int(sg.user_settings_get_entry('-current count-', 0))
353 current_goal = int(sg.user_settings_get_entry('-goal-', 100))
354 current_goal = current_goal if current_goal != 0 else 100
355 except:
356 if sg.popup_yes_no('Your count or goal number is not good. Do you want to delete your settings file?', location=window.current_location()) == 'Yes':
357 sg.user_settings_delete_filename()
358 sg.popup('Settings deleted.','Please restart your program', location=window.current_location())
359 exit()
360
361 window['-MAIN INFO-'].update(current_count)
362 window['-GOAL-'].update(current_goal)
363
364 while True: # Event Loop
365 window.gauge.change()
366 new_angle = current_count / current_goal * 180
367 window.gauge.change(degree=new_angle, step=180)
368 window.gauge.change()
369 window['-GOAL-'].update(current_goal)
370 window['-MAIN INFO-'].update(current_count)
371
372 # -------------- Start of normal event loop --------------
373 event, values = window.read()
374 print(event, values)
375 if event == sg.WIN_CLOSED or event == 'Exit':
376 break
377 if event == 'Edit Me':
378 sg.execute_editor(__file__)
379 elif event == 'Set Count':
380 new_count = sg.popup_get_text('Enter current count', default_text=current_count, location=window.current_location(), keep_on_top=True)
381 if new_count is not None:
382 try:
383 current_count = int(new_count)
384 except:
385 sg.popup_error('Your count is not good. Ignoring input.', location=window.current_location())
386 continue
387 sg.user_settings_set_entry('-current count-', current_count)
388 elif event == 'Set Goal':
389 new_goal = sg.popup_get_text('Enter Goal', default_text=current_goal, location=window.current_location(), keep_on_top=True)
390 if new_goal is not None:
391 try:
392 current_goal = int(new_goal)
393 except:
394 sg.popup_error('Your goal number is not good. Ignoring input.', location=window.current_location())
395 continue
396 current_goal = current_goal if current_goal != 0 else 100
397 sg.user_settings_set_entry('-goal-', current_goal)
398 elif event == 'Choose Title':
399 new_title = sg.popup_get_text('Choose a title for your date', default_text=sg.user_settings_get_entry('-title-', '') , location=window.current_location(), keep_on_top=True)
400 if new_title is not None:
401 window['-TITLE-'].update(new_title)
402 sg.user_settings_set_entry('-title-', new_title)
403 elif event == 'Save Location':
404 sg.user_settings_set_entry('-location-', window.current_location())
405 elif event in [str(x) for x in range(1,11)]:

Calls 8

current_locationMethod · 0.80
set_alphaMethod · 0.80
make_windowFunction · 0.70
choose_themeFunction · 0.70
updateMethod · 0.45
changeMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected