From e5e90d5ea6cad14e3265fb57db5cc9047ab9996e Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Mon, 9 Aug 2021 16:45:22 -0400 Subject: [PATCH] New Demo Program - Text Element - new fully autosize --- DemoPrograms/Demo_Text_Element_Autosize.py | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 DemoPrograms/Demo_Text_Element_Autosize.py diff --git a/DemoPrograms/Demo_Text_Element_Autosize.py b/DemoPrograms/Demo_Text_Element_Autosize.py new file mode 100644 index 00000000..93f1ef1e --- /dev/null +++ b/DemoPrograms/Demo_Text_Element_Autosize.py @@ -0,0 +1,46 @@ +import PySimpleGUI as sg + +""" + Demo of autosize of Text Element + + Beginning in version 4.46.0 the Text element will fully autosize if: + * auto_size_text is True (default) + * No size is supplied or (None, None) is supplied + + "Fully autosize" means that both the element and the window will grow/shrink + as the contents of the Text element changes. + + Prior versions autosized in 1 direction, either horizontally or vertically + * Set size = (None, int) to autosize horizontally + * Set size = (int, None) to autosize vertically + + By default autosize is enabled, but setting a size parameter will disable unless None is specified + in one of the directions. + + Copyright 2021 PySimpleGUI +""" + +layout = [[sg.Text('Starting string', size=(None, None), k='-T-'), sg.Text('Also on first row')], + # THIS is the newly added combination. Note (None, None) is default and not really needed + [sg.Text('None, 1', size=(None, 1), k='-T1-'), sg.Text('rest of the row')], + [sg.Text('30, None', size=(30, None), k='-T2-'), sg.Text('rest of the row')], + [sg.Text('Explicit size', size=(15, 1)), sg.Text('Second Text Element on second row')], + [sg.Button('Go'), sg.B('Clear'), sg.Button('Exit')]] + +window = sg.Window('Autosize Text', layout) + +while True: + event, values = window.read() + print(event, values) + if event == sg.WIN_CLOSED or event == 'Exit': + break + if event == 'Go': + window['-T-'].update('This is the new string\nThat is multiple\nlines') + window['-T1-'].update('This is the new string\nThat is multiple\nlines') + window['-T2-'].update('This is the new string\nThat is multiple\nlines') + elif event == 'Clear': + window['-T-'].update('') + window['-T1-'].update('') + window['-T2-'].update('') + +window.close()