PySimpleGUI/ProgrammingClassExamples/MacOS versions/2a. PSG (checkbox and radio...

50 lines
1.7 KiB
Python
Raw Normal View History

2018-11-13 15:33:55 +00:00
#PySimple examples (v 3.9)
#Tony Crewe
2018-11-13 15:33:55 +00:00
#Oct 2018 MacOs
import PySimpleGUI as sg
#Set colour scheme and font
2018-11-13 15:33:55 +00:00
#sg.ChangeLookAndFeel('GreenTan')
2018-11-13 15:33:55 +00:00
sg.SetOptions (background_color = 'LightPink',
element_background_color = 'LightPink',
text_element_background_color = 'LightPink',
font = ('Arial', 14, 'bold'),
text_color = 'Green',
input_text_color ='Green',
button_color = ('Green', 'White'))
#One checkbox and three radio buttons (grouped as 'Radio1')
#value[0] - checkbox, Value[1-3] radiobutton selection
layout = [[sg.Text('Membership Calculator', font = ('Calibri', 16, 'bold'))],
[sg.Checkbox(' Student? 10% off', size = (25,1)),
sg.ReadButton('Display Cost', size = (14,1))],
[sg.Radio('1 month $50', 'Radio1', default = True),
sg.Radio('3 months $100', 'Radio1'),
sg.Radio('1 year $300', 'Radio1')],
[sg.Text('', size = (30,1), justification = 'center', font =('Calibri', 16, 'bold'), key = 'result')]]
window = sg.Window('Gym Membership').Layout(layout)
while True:
button, value = window.Read()
if button is not None:
if value[1]:
cost = 50
elif value[2]:
cost = 100
else:
cost = 300
if value[0]:
#apply discount
cost = cost*0.9
#format as currency $ symbol and 2 d.p. - make a string
result = str(' Cost: ' + '${:.2f}'.format(cost))
#put the result in Textbox
window.FindElement('result').Update(result)
else:
break