Fix for missing font on debug print. Addition of font to Multiline demo program

This commit is contained in:
PySimpleGUI 2021-06-10 10:47:31 -04:00
parent 00fa20e13b
commit ee2a1ba22c
2 changed files with 24 additions and 15 deletions

View file

@ -1,37 +1,46 @@
import PySimpleGUI as sg
# import PySimpleGUIQt as sg
print(sg.version)
"""
Demonstration of how to work with multiple colors when outputting text to a multiline element
Demonstration of how to work with multiple colors and fonts when outputting text to a multiline element or with Debug Print
Copyright 2021 PySimpleGUI
"""
MLINE_KEY = '-MLINE-'+sg.WRITE_ONLY_KEY
MLINE_KEY = '-MLINE-'
layout = [ [sg.Text('Demonstration of Multiline Element\'s ability to show multiple colors ')],
[sg.Multiline(size=(60,20), key=MLINE_KEY)],
[sg.Multiline(size=(60,20), key=MLINE_KEY, reroute_cprint=True, write_only=True)],
[sg.Input(k='-IN-')],
[sg.B('Plain'), sg.Button('Text Blue Line'), sg.Button('Text Green Line')],
[sg.Button('Background Blue Line'),sg.Button('Background Green Line'), sg.B('White on Green')] ]
[sg.Button('Background Blue Line'),sg.Button('Background Green Line'), sg.B('White on Green'), sg.B('Font Courier 12')] ]
window = sg.Window('Demonstration of Multicolored Multline Text', layout)
# print = lambda *args, **kwargs: window[MLINE_KEY].print(*args, **kwargs, text_color='red')
mline:sg.Multiline = window[MLINE_KEY]
while True:
event, values = window.read() # type: (str, dict)
print(event, values)
sg.cprint(event, values, c='white on green', font='courier 12')
sg.Print(event, c='white on green', font='courier 12', end='')
sg.Print(values, c='white on red', font='Courier 12 underline italic bold', end='')
sg.Print('')
if event in (sg.WIN_CLOSED, 'Exit'):
break
if 'Text Blue' in event:
window[MLINE_KEY].update('This is blue text\n', text_color_for_value='blue', append=True)
mline.update('This is blue text\n', text_color_for_value='blue', append=True)
if 'Text Green' in event:
window[MLINE_KEY].update('This is green text\n', text_color_for_value='green', append=True)
mline.update('This is green text\n', text_color_for_value='green', append=True)
if 'Background Blue' in event:
window[MLINE_KEY].update('This is Blue Background\n', background_color_for_value='blue', append=True)
mline.update('This is Blue Background\n', background_color_for_value='blue', append=True)
if 'Background Green' in event:
window[MLINE_KEY].update('This is Green Background\n', background_color_for_value='green', append=True)
mline.update('This is Green Background\n', background_color_for_value='green', append=True)
if 'Font' in event:
mline.update('This is Green Background\n', background_color_for_value='green', append=True, font_for_value=('Courier', 12, 'underline'))
mline.print('\nThis is Green Background\n', c='white on green', font='Courier 12 bold ')
if 'White on Green' in event:
window[MLINE_KEY].update('This is white text on a green background', text_color_for_value='white', background_color_for_value='green', append=True)
mline.update('This is white text on a green background\n', text_color_for_value='white', background_color_for_value='green', append=True)
if event == 'Plain':
window[MLINE_KEY].update('This is plain text with no extra coloring', append=True)
mline.update('This is plain text with no extra coloring\n', append=True)
window.close()