From 578ea55696ea56e2f1f78c9c11ecfaf84c15f75d Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sun, 1 Dec 2019 15:54:29 -0500 Subject: [PATCH] New demo! Multiline Element - how to use multiple colors for text --- .../Demo_Multiline_Multicolored_Text.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 DemoPrograms/Demo_Multiline_Multicolored_Text.py diff --git a/DemoPrograms/Demo_Multiline_Multicolored_Text.py b/DemoPrograms/Demo_Multiline_Multicolored_Text.py new file mode 100644 index 00000000..345d7c75 --- /dev/null +++ b/DemoPrograms/Demo_Multiline_Multicolored_Text.py @@ -0,0 +1,35 @@ +import PySimpleGUI as sg +# import PySimpleGUIQt as sg + +""" + Demonstration of how to work with multiple colors when outputting text to a multiline element +""" + +sg.change_look_and_feel('Dark Blue 3') + +MLINE_KEY = '-MLINE-'+sg.WRITE_ONLY_KEY +layout = [ [sg.Text('Demonstration of Multiline Element\'s ability to show multiple colors ')], + [sg.Multiline(size=(60,20), key=MLINE_KEY)], + [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') + ] ] + +window = sg.Window('Demonstration of Multicolored Multline Text', layout) + +while True: + event, values = window.read() # type: (str, dict) + print(event, values) + if event in (None, 'Exit'): + break + if 'Text Blue' in event: + window[MLINE_KEY].update('This is blue text', text_color_for_value='blue', append=True) + if 'Text Green' in event: + window[MLINE_KEY].update('This is green text', text_color_for_value='green', append=True) + if 'Background Blue' in event: + window[MLINE_KEY].update('This is Blue Background', background_color_for_value='blue', append=True) + if 'Background Green' in event: + window[MLINE_KEY].update('This is Green Backgroundt', background_color_for_value='green', append=True) + 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) + if event == 'Plain': + window[MLINE_KEY].update('This is plain text with no extra coloring', append=True) +window.close()