Python Forum
[PySimpleGUI] error trying to resize Text element
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PySimpleGUI] error trying to resize Text element
#1
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
Reply
#2
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.
Reply
#3
ok,
if there are no solutions, I moved to a display in a popup window.

thanks FullOfHelp
Reply
#4
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Can't get MDIarea to resize automatically with Main Window JayCee 4 3,395 Aug-02-2021, 08:47 PM
Last Post: JayCee
  how to resize image in canvas tkinter samuelmv30 2 17,553 Feb-06-2021, 03:35 PM
Last Post: joe_momma
  [PyQt] dynamically resize custom widget fill remaining space ironcthulhu 1 11,213 Dec-31-2019, 09:45 PM
Last Post: Denni
  [PySimpleGUI] New input replacing default value in InputText Element skratt 1 11,340 Nov-16-2019, 06:38 PM
Last Post: FullOfHelp
  [Tkinter] Display Selected Image from Directory and Resize it EchoLi 0 4,196 Oct-02-2019, 06:54 PM
Last Post: EchoLi
  [Tkinter] not resize a frame Scorpio 2 3,488 Mar-13-2019, 11:24 PM
Last Post: Scorpio
  [PyQt] Resize button with window resize FesterJester 2 9,688 Dec-03-2018, 12:02 AM
Last Post: FesterJester

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020