How to change the popup size in PysimpleGUI in python?

5.4k views Asked by At

I am using PYsimpleGUI in my python code, and while using the popup element how do you resize the popup window?

My code:

import PySimpleGUI as sg
sg.popup("Hello!")

How to resize sg.popup?

Also, is there an option to add a title to the popup window?

4

There are 4 answers

1
Gonenc On BEST ANSWER

Unfortunately there is no size parameter in sg.popup, however you can adjust the size of the window by changing the contents of the text shown, ie. longer string and some empty lines.

Another option would be creating a new pop up funtion that works similar to the sg.popup but based on sg.Window object. This way you can be more flexible with the parameters.

You can add the title by using the title parameter: sg.popup('world', title='hello')

0
AzyCrw4282 On

To resize while using the element, you can do that by using the Stretch element to push stuff around.

To set the title, it's simple as

import PySimpleGUI as sg
# Create the Window
window = sg.Window('Window Title', layout)

If you are new to the library, the documentation is a great place to start.

0
Tarqez On

As already answered there is no size parameter for the sg.popup() function and you can use spaces and empty strings like paddings this way:

import PySimpleGUI as sg

# blanks like paddings example
sg.popup("", "          Hello!          \x00", "")

the empty strings before and after Hello! behave like vertical padding while the spaces inside Hello! string behave like horizontal padding.

Now you could ask why the hex escape character \x00?

It's the workaround I found, stands for the Null character and without it doesn't pad on the right.

0
SaezM On

You can use the popup scrolled to create a popup with size attributes:

example:

sg.popup_scrolled("Qty NOW: 12\nQty Initial: 11\nPN: CamposFields\nStatus: Start", 
                  title="Running checks...", 
                  auto_close=True, 
                  auto_close_duration=10, 
                  size=(30, 10)
                  )