2018-08-31 13:10:15 +00:00
|
|
|
|
2018-08-31 13:29:00 +00:00
|
|
|
# Testing async form, see if can have a slider
|
2018-08-31 13:10:15 +00:00
|
|
|
# that adjusts the size of text displayed
|
|
|
|
|
|
|
|
import PySimpleGUI as sg
|
|
|
|
|
|
|
|
form = sg.FlexForm("Font size selector")
|
|
|
|
|
|
|
|
fontSize = 12
|
|
|
|
sampleText = sg.Text("Aa", size=(2, 1), font="Helvetica " + str(fontSize))
|
2018-09-01 15:37:36 +00:00
|
|
|
slider = sg.Slider(range=(6,50), orientation='h', size=(10,20), change_submits=True, key='slider')
|
2018-08-31 13:29:00 +00:00
|
|
|
spin = sg.Spin([sz for sz in range(4,72)], font=('Helvetica 20'), initial_value=fontSize, change_submits=True, key='spin')
|
2018-08-31 13:10:15 +00:00
|
|
|
layout = [
|
2018-08-31 13:29:00 +00:00
|
|
|
[sampleText, spin, slider],
|
2018-08-31 13:10:15 +00:00
|
|
|
[sg.OK(), sg.Cancel()]
|
|
|
|
]
|
|
|
|
|
|
|
|
sz = fontSize
|
|
|
|
form.Layout(layout)
|
|
|
|
while True:
|
|
|
|
button, values= form.Read()
|
2018-09-01 14:51:19 +00:00
|
|
|
if button in (None, 'OK', 'Cancel'):
|
2018-08-31 13:10:15 +00:00
|
|
|
break
|
2018-08-31 13:29:00 +00:00
|
|
|
sz_spin = int(values['spin'])
|
|
|
|
sz_slider = int(values['slider'])
|
|
|
|
sz = sz_spin if sz_spin != fontSize else sz_slider
|
2018-08-31 13:10:15 +00:00
|
|
|
if sz != fontSize:
|
2018-08-31 13:29:00 +00:00
|
|
|
print(sampleText.Font, sampleText.Size)
|
2018-08-31 13:10:15 +00:00
|
|
|
fontSize = sz
|
|
|
|
font = "Helvetica " + str(fontSize)
|
|
|
|
sampleText.Update(font=font)
|
2018-08-31 13:29:00 +00:00
|
|
|
slider.Update(sz)
|
|
|
|
spin.Update(sz)
|
2018-08-31 13:10:15 +00:00
|
|
|
|
|
|
|
print("Done.")
|