2018-10-18 04:13:33 +00:00
|
|
|
#!/usr/bin/env python
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-10-18 04:13:33 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
'''
|
2022-01-23 11:39:46 +00:00
|
|
|
Demo Font Previewer
|
|
|
|
|
|
|
|
Gets a list of the installed fonts according to tkinter.
|
|
|
|
Requires PySimpleGUI version 4.57.0 and newer (that's when sg.Text.fonts_installed_list was added)
|
|
|
|
|
|
|
|
Uses the Text element's class method to get the fonts reported by tkinter.
|
|
|
|
|
|
|
|
Copyright 2020, 2021, 2022 PySimpleGUI
|
2019-10-23 20:10:03 +00:00
|
|
|
'''
|
2018-10-18 04:13:33 +00:00
|
|
|
|
2022-01-23 11:39:46 +00:00
|
|
|
fonts = sg.Text.fonts_installed_list()
|
|
|
|
|
|
|
|
|
2019-12-24 23:52:47 +00:00
|
|
|
sg.theme('Black')
|
2018-10-18 04:13:33 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
layout = [[sg.Text('My Text Element',
|
|
|
|
size=(20, 1),
|
|
|
|
click_submits=True,
|
|
|
|
relief=sg.RELIEF_GROOVE,
|
|
|
|
font='Courier` 25',
|
|
|
|
text_color='#FF0000',
|
|
|
|
background_color='white',
|
|
|
|
justification='center',
|
|
|
|
pad=(5, 3),
|
|
|
|
key='-text-',
|
|
|
|
tooltip='This is a text element',
|
|
|
|
)],
|
|
|
|
[sg.Listbox(fonts, size=(30, 20), change_submits=True, key='-list-')],
|
|
|
|
[sg.Input(key='-in-')],
|
|
|
|
[sg.Button('Read', bind_return_key=True), sg.Exit()]]
|
2018-10-18 04:13:33 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window = sg.Window('My new window', layout)
|
2018-10-18 04:13:33 +00:00
|
|
|
|
|
|
|
while True: # Event Loop
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
2020-05-07 10:22:59 +00:00
|
|
|
if event in (sg.WIN_CLOSED, 'Exit'):
|
2018-10-18 04:13:33 +00:00
|
|
|
break
|
2019-10-23 20:10:03 +00:00
|
|
|
text_elem = window['-text-']
|
2018-10-18 04:13:33 +00:00
|
|
|
print(event, values)
|
2019-10-23 20:10:03 +00:00
|
|
|
if values['-in-'] != '':
|
|
|
|
text_elem.update(font=values['-in-'])
|
2018-10-18 04:13:33 +00:00
|
|
|
else:
|
2019-10-23 20:10:03 +00:00
|
|
|
text_elem.update(font=(values['-list-'][0], 25))
|
|
|
|
window.close()
|