Python Forum

Full Version: [PySimpleGUI] error trying to resize Text element
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I just spent 3 hours on something I cannot understand:

I'm trying to re-size a Text element, but it replies me :

Quote:window.Element('-DISPLAY-').Update(size = (45,nb_lines))
TypeError: Update() got an unexpected keyword argument 'size'

It is very strange as text elements has a size argument.

Here is the code:
mycolumn =[      
            [sg.InputText(,key='-VOLUME-',focus=True)],      
            [],
            [sg.InputText(key='-SOLUTION-',size=(45,3))],      
            [],
            [sg.Button('Display')]]
          
layout =[ [sg.Text("Nothing to display",key='-DISPLAY-',size=(20,5)),sg.Column(mycolumn)]]      

window = sg.Window('Display of a solution', layout).Finalize()    

while True:    
    event, values = window.Read()    
        
    if event in (None, 'Quit'):
        # logger.warning("User manual exit")
        break
        if event == 'Display':
            displayed_message = mystring
            nb_lines = 1+2*displayed_message.count("]]") 
            window.Element('-DISPLAY-').Update(displayed_message) 
            window.Element('-DISPLAY-').Update(size = (45,nb_lines))
window.Close()
the update of displayed_message works ok, but the other trows at me the error message
Quote:window.Element('-DISPLAY-').Update(size = (45,nb_lines))
TypeError: Update() got an unexpected keyword argument 'size'

I have tried finalizing window (even if I'm reading it before the update so that should not be mandatory,
I've tried passing the tyo arguments at the same time,

I went for hours to find a solution in the documentation and on internet without any result. Wall Wall Wall

Any idea ?

Thanks in advance
The answers you're looking for can be found in the main documentation, in the section that details each of the method calls for each element. The Text Element's info is located here:
https://pysimplegui.readthedocs.io/en/la...xt-element

You'll find the Update method detailed there. What you'll see is that the reason for the error is that there is no size field in the update call for the Text Element. Not every parameter used to create an element can be updated. Size is one of them for a Text Element.
ok,
if there are no solutions, I moved to a display in a popup window.

thanks FullOfHelp
You can now resize text elements, or any element, by calling the set_size method.

To do what you were trying to do, you code would now read:
window['-DISPLAY-'].set_size((45,nb_lines))
It's a relatively new addition to the package (released in 4.5 in Nov of this year)

Questions like these sometimes get turned into enhancements / new features. You're encouraged to ask / suggest on the project's GitHub page under Issues (http://www.PySimpleGUI.com)