2018-11-13 15:33:55 +00:00
|
|
|
#PySimple examples (v 3.9)
|
2018-09-27 09:18:35 +00:00
|
|
|
#Tony Crewe
|
2018-11-13 15:33:55 +00:00
|
|
|
#Oct 2018 MacOs
|
2018-09-27 09:18:35 +00:00
|
|
|
|
|
|
|
import PySimpleGUI as sg
|
|
|
|
|
2018-11-13 15:33:55 +00:00
|
|
|
sg.SetOptions (background_color = 'LightPink',
|
|
|
|
element_background_color = 'LightPink',
|
|
|
|
text_element_background_color = 'LightPink',
|
|
|
|
font = ('Calibri', 14, 'bold'),
|
|
|
|
text_color = 'Black',
|
|
|
|
input_text_color ='Black',
|
|
|
|
button_color = ('Black', 'White'))
|
2018-09-28 18:57:37 +00:00
|
|
|
#use of Column to help with layout - vertical sliders take up space
|
|
|
|
|
2018-09-27 09:18:35 +00:00
|
|
|
column1 = [
|
2018-11-13 15:33:55 +00:00
|
|
|
[sg.Text('Pick operation', size = (15,1), font = ('Calibri', 16, 'bold'))],
|
|
|
|
[sg.InputCombo(['Add','Subtract','Multiply','Divide'], size = (10,8))],
|
2018-09-27 09:18:35 +00:00
|
|
|
[sg.Text('', size =(1,4))]]
|
|
|
|
column2 = [
|
2018-11-13 15:33:55 +00:00
|
|
|
[sg.ReadButton('Submit', font = ('Calibri', 16, 'bold'), size = (8, 1))],
|
|
|
|
[sg.Text('Result:', font = ('Calibri', 16, 'bold'))],[sg.InputText(size = (12,1), key = '_result_')]
|
2018-09-27 09:18:35 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
layout = [
|
2018-11-13 15:33:55 +00:00
|
|
|
[sg.Text('Slider and Combo box demo', font = ('Calibri', 16,'bold'))],
|
2018-09-27 09:18:35 +00:00
|
|
|
[sg.Slider(range = (-9, 9),orientation = 'v', size = (5,20), default_value = 0),
|
|
|
|
sg.Slider(range = (-9, 9),orientation = 'v', size = (5, 20), default_value = 0),
|
2018-10-08 05:36:38 +00:00
|
|
|
sg.Text(' '), sg.Column(column1), sg.Column(column2)]]
|
2018-09-27 09:18:35 +00:00
|
|
|
|
2018-09-28 18:57:37 +00:00
|
|
|
#added grab_anywhere to when moving slider, who window doesn't move.
|
|
|
|
|
|
|
|
window = sg.Window('Enter & Display Data',grab_anywhere = False).Layout(layout)
|
2018-09-27 09:18:35 +00:00
|
|
|
|
2018-09-28 18:57:37 +00:00
|
|
|
#Get selection from combo: value[2]
|
|
|
|
#Slider values: value[0] and value[1]
|
2018-09-27 09:18:35 +00:00
|
|
|
while True:
|
|
|
|
button, value = window.Read()
|
|
|
|
if button is not None:
|
|
|
|
if value[2] == 'Add':
|
|
|
|
result = value[0] + value[1]
|
|
|
|
elif value[2] == 'Multiply':
|
|
|
|
result = value[0] * value[1]
|
|
|
|
elif value[2] == 'Subtract':
|
|
|
|
result = value[0] - value[1]
|
2018-09-28 18:57:37 +00:00
|
|
|
elif value[2] == 'Divide': #check for zero
|
2018-09-27 09:18:35 +00:00
|
|
|
if value[1] ==0:
|
|
|
|
sg.Popup('Second value can\'t be zero')
|
2018-09-28 18:57:37 +00:00
|
|
|
result = 'NA'
|
2018-09-27 09:18:35 +00:00
|
|
|
else:
|
|
|
|
result = value[0] / value[1]
|
2018-10-08 05:36:38 +00:00
|
|
|
window.FindElement('_result_').Update(result)
|
2018-09-27 09:18:35 +00:00
|
|
|
else:
|
|
|
|
break
|