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

Function main

DemoPrograms/Demo_Graph_pymunk_2D_Graphics.py:66–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

64
65
66def main():
67
68
69
70 # ------------------- Build and show the GUI Window -------------------
71 graph_elem = sg.Graph((600, 400), (0, 400), (600, 0),
72 enable_events=True, key='-GRAPH-', background_color='lightblue')
73
74 hostname = socket.gethostbyname(socket.gethostname())
75 layout = [[sg.Text('Ball Test'), sg.Text('My IP '+hostname)],
76 [graph_elem],
77 # [sg.Up(), sg.Down()],
78 [sg.Button('Kick'), sg.Button('Exit')]]
79
80 window = sg.Window('Window Title', layout, finalize=True)
81
82 area = Playfield(graph_elem)
83 area.add_balls()
84
85 # ------------------- GUI Event Loop -------------------
86 while True: # Event Loop
87 event, values = window.read(timeout=0)
88 # print(event, values)
89 if event in (sg.WIN_CLOSED, 'Exit'):
90 break
91 area.space.step(0.02)
92
93 for ball in area.arena_balls:
94 if event == 'Kick':
95 ball.body.position = ball.body.position[0], ball.body.position[1]-random.randint(
96 1, 200)
97 graph_elem.RelocateFigure(
98 ball.gui_circle_figure, ball.body.position[0], ball.body.position[1])
99
100 window.close()
101
102if __name__ == '__main__':
103 main()

Calls 4

add_ballsMethod · 0.95
readMethod · 0.95
closeMethod · 0.95
PlayfieldClass · 0.70

Tested by

no test coverage detected