2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
2018-09-28 18:57:37 +00:00
|
|
|
if sys.version_info[0] >= 3:
|
2018-09-27 20:24:09 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-28 18:57:37 +00:00
|
|
|
else:
|
|
|
|
import PySimpleGUI27 as sg
|
2018-08-26 19:29:12 +00:00
|
|
|
|
|
|
|
layout = [
|
2018-09-18 16:05:44 +00:00
|
|
|
[sg.Canvas(size=(150, 150), background_color='red', key='canvas')],
|
2018-09-24 22:01:00 +00:00
|
|
|
[sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue')]
|
2018-08-26 19:29:12 +00:00
|
|
|
]
|
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
window = sg.Window('Canvas test').Layout(layout).Finalize()
|
2018-08-26 19:29:12 +00:00
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
cir = window.FindElement('canvas').TKCanvas.create_oval(50, 50, 100, 100)
|
2018-08-26 19:29:12 +00:00
|
|
|
|
|
|
|
while True:
|
2018-10-15 20:07:23 +00:00
|
|
|
event, values = window.Read()
|
|
|
|
if event is None:
|
2018-09-04 23:43:22 +00:00
|
|
|
break
|
2018-10-15 20:07:23 +00:00
|
|
|
if event is 'Blue':
|
2018-09-24 22:01:00 +00:00
|
|
|
window.FindElement('canvas').TKCanvas.itemconfig(cir, fill = "Blue")
|
2018-10-15 20:07:23 +00:00
|
|
|
elif event is 'Red':
|
2018-09-24 22:01:00 +00:00
|
|
|
window.FindElement('canvas').TKCanvas.itemconfig(cir, fill = "Red")
|