2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-18 15:10:17 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
# Usage of Graph element.
|
2018-09-18 15:10:17 +00:00
|
|
|
|
2019-12-24 23:52:47 +00:00
|
|
|
layout = [[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0, 0), graph_top_right=(400, 400), background_color='red', enable_events=True, key='graph')],
|
2019-10-23 20:10:03 +00:00
|
|
|
[sg.Text('Change circle color to:'), sg.Button('Red'), sg.Button('Blue'), sg.Button('Move')]]
|
2018-09-18 15:10:17 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window = sg.Window('Graph test', layout, finalize=True)
|
|
|
|
|
2020-05-07 10:22:59 +00:00
|
|
|
graph = window['graph'] # type: sg.Graph
|
2019-10-23 20:10:03 +00:00
|
|
|
circle = graph.draw_circle((75, 75), 25, fill_color='black', line_color='white')
|
|
|
|
point = graph.draw_point((75, 75), 10, color='green')
|
|
|
|
oval = graph.draw_oval((25, 300), (100, 280), fill_color='purple', line_color='purple')
|
|
|
|
rectangle = graph.draw_rectangle((25, 300), (100, 280), line_color='purple')
|
|
|
|
line = graph.draw_line((0, 0), (100, 100))
|
|
|
|
arc = graph.draw_arc((0, 0), (400, 400), 160, 10, style='arc', arc_color='blue')
|
2020-05-07 10:22:59 +00:00
|
|
|
poly = graph.draw_polygon(((10,10), (20,0), (40,200), (10,10)), fill_color='green')
|
2018-09-18 15:10:17 +00:00
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
2019-12-24 23:52:47 +00:00
|
|
|
print(event, values)
|
2020-05-07 10:22:59 +00:00
|
|
|
if event == sg.WIN_CLOSED:
|
2018-09-18 15:10:17 +00:00
|
|
|
break
|
2019-06-26 15:09:42 +00:00
|
|
|
if event in ('Blue', 'Red'):
|
|
|
|
graph.TKCanvas.itemconfig(circle, fill=event)
|
|
|
|
elif event == 'Move':
|
2019-10-23 20:10:03 +00:00
|
|
|
graph.MoveFigure(point, 10, 10)
|
|
|
|
graph.MoveFigure(circle, 10, 10)
|
|
|
|
graph.MoveFigure(oval, 10, 10)
|
|
|
|
graph.MoveFigure(rectangle, 10, 10)
|
|
|
|
graph.MoveFigure(arc, 10, 10)
|
2020-05-07 10:22:59 +00:00
|
|
|
graph.MoveFigure(poly, 10, 10)
|
2019-10-23 20:10:03 +00:00
|
|
|
|
|
|
|
window.close()
|