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

Function main

DemoPrograms/Demo_Graph_pymunk_Desktop_Balls.py:56–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54
55
56def main():
57 screensize = sg.Window.get_screen_size()
58
59 # ------------------- Build and show the GUI Windows -------------------
60 graph_elem = sg.Graph(screensize, (0, screensize[1]), (screensize[0], 0),
61 enable_events=True, key='-GRAPH-', background_color='lightblue')
62 layout = [[graph_elem]]
63 window1 = sg.Window('Bouncing Balls', layout, finalize=True, location=(0,0), keep_on_top=True, element_padding=(0,0), margins=(0,0), no_titlebar=True, right_click_menu=[[''], ['Front', 'Back', 'Controls', 'Exit']])
64
65 area = Playfield(graph_elem, screensize)
66 area.add_balls()
67 transparent, paused = False, True
68 layout2 = [[sg.B('❎', border_width=0, button_color=('white', sg.theme_background_color()), key='Exit')],[sg.B('Kick'), sg.B('Front'), sg.B('Back'), sg.B('More Balls'),sg.B('Transparent'), sg.B('Resume', key='Pause')]]
69 window2 = sg.Window('Buttons', layout2, keep_on_top=True, grab_anywhere=True, no_titlebar=True, finalize=True)
70
71
72
73 # ------------------- GUI Event Loop -------------------
74 while True:
75 window, event, values = sg.read_all_windows(timeout=0)
76 if event in (sg.WIN_CLOSED, 'Exit'):
77 break
78
79 if event == 'More Balls':
80 area.add_balls()
81 elif event == 'Kick':
82 for ball in area.arena_balls:
83 ball.body.position = ball.body.position[0], ball.body.position[1]-random.randint(200,400)
84 elif event == 'Front':
85 window1.bring_to_front()
86 elif event == 'Back':
87 window1.send_to_back()
88 elif event == 'Transparent':
89 window1.set_transparent_color('lightblue' if not transparent else 'black')
90 transparent = not transparent
91 elif event == 'Controls':
92 window2.bring_to_front()
93 elif event == 'Pause':
94 paused = not paused
95 window['Pause'].update(text='Resume' if paused else 'Pause')
96
97 if paused:
98 continue
99
100 area.space.step(0.02)
101
102 for ball in area.arena_balls:
103 if ball.body.position[1] > screensize[1]:
104 ball.body.position = ball.body.position[0],screensize[1]-30
105
106 graph_elem.RelocateFigure(
107 ball.gui_circle_figure, ball.body.position[0], ball.body.position[1])
108
109 window1.close()
110 window2.close()
111
112if __name__ == '__main__':
113 main()

Calls 8

add_ballsMethod · 0.95
bring_to_frontMethod · 0.95
send_to_backMethod · 0.95
set_transparent_colorMethod · 0.95
closeMethod · 0.95
get_screen_sizeMethod · 0.80
PlayfieldClass · 0.70
updateMethod · 0.45

Tested by

no test coverage detected