2018-10-15 20:07:23 +00:00
|
|
|
#!/usr/bin/env python
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-10-15 20:07:23 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
'''
|
|
|
|
App that shows "how fonts work in PySimpleGUI".
|
|
|
|
'''
|
|
|
|
|
|
|
|
layout = [[sg.Text('This is my sample text', size=(20, 1), key='-text-')],
|
|
|
|
[sg.CB('Bold', key='-bold-', change_submits=True),
|
|
|
|
sg.CB('Italics', key='-italics-', change_submits=True),
|
|
|
|
sg.CB('Underline', key='-underline-', change_submits=True)],
|
|
|
|
[sg.Slider((6, 50), default_value=12, size=(14, 20),
|
|
|
|
orientation='h', key='-slider-', change_submits=True),
|
2018-10-15 20:07:23 +00:00
|
|
|
sg.Text('Font size')],
|
2019-10-23 20:10:03 +00:00
|
|
|
[sg.Text('Font string = '), sg.Text('', size=(25, 1), key='-fontstring-')],
|
|
|
|
[sg.Button('Exit')]]
|
2018-10-15 20:07:23 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window = sg.Window('Font string builder', layout)
|
2018-10-15 20:07:23 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
text_elem = window['-text-']
|
2018-10-15 20:07:23 +00:00
|
|
|
while True: # Event Loop
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
2018-10-15 20:07:23 +00:00
|
|
|
if event in (None, 'Exit'):
|
|
|
|
break
|
|
|
|
font_string = 'Helvitica '
|
2019-10-23 20:10:03 +00:00
|
|
|
font_string += str(values['-slider-'])
|
|
|
|
if values['-bold-']:
|
2018-10-15 20:07:23 +00:00
|
|
|
font_string += ' bold'
|
2019-10-23 20:10:03 +00:00
|
|
|
if values['-italics-']:
|
2018-10-15 20:07:23 +00:00
|
|
|
font_string += ' italic'
|
2019-10-23 20:10:03 +00:00
|
|
|
if values['-underline-']:
|
2018-10-15 20:07:23 +00:00
|
|
|
font_string += ' underline'
|
2019-10-23 20:10:03 +00:00
|
|
|
text_elem.update(font=int(font_string.split(' ')[1].split('.')[0]))
|
|
|
|
window['-fontstring-'].update('"'+font_string+'"')
|
2018-10-15 20:07:23 +00:00
|
|
|
print(event, values)
|
2019-10-23 20:10:03 +00:00
|
|
|
|
|
|
|
window.close()
|