Pysimplegui: [Question] Remove "Ok" button from popup

Created on 14 Feb 2020  ·  3Comments  ·  Source: PySimpleGUI/PySimpleGUI

Question

I want to remove the "Ok" button packed by default with my simple popup (using popup with no title bar).

Operating System

Arch Linux

Python version

3.8.1

PySimpleGUI Port and Version

4.15.2

Your Experience Levels In Months or Years

1 month
5 Python programming experience
8 years of Programming experience overall
yes (tk) Have used another Python GUI Framework (tkiner, Qt, etc) previously (yes/no is fine)?

Most helpful comment

Found the solution by taking a look at source code (psg).
Just provide the button_type argument like this:

sg.Popup("This is a simple popup", button_type=5)

In PySimpleGUI there are 5 types of button configurations:

Yes, No: 1
Cancel: 2
Error: 3
Ok, cancel: 4
No button: 5

All 3 comments

Found the solution by taking a look at source code (psg).
Just provide the button_type argument like this:

sg.Popup("This is a simple popup", button_type=5)

In PySimpleGUI there are 5 types of button configurations:

Yes, No: 1
Cancel: 2
Error: 3
Ok, cancel: 4
No button: 5

I crack up when people ask for changes to popup.

Don't be afraid of making your own popup / window. You can create, display, read and close a window in a single line of code now by using the close parameter. Otherwise it's 3 lines of code. Create, read, close. When it's this simple to create your own windows you don't need modifications to popup... you can easily make your own, in-line.

I'm curious how you are going to close your window if it has no buttons an no titlebar.

You can also call popup_no_buttons. This is why the button parameter exists. It's not meant to be something user accessible according to the doc string:

    :param button_type: (enum) NOT USER SET!  Determines which pre-defined buttons will be shown (Default value = POPUP_BUTTONS_OK). There are many Popup functions and they call Popup, changing this parameter to get the desired effect.

If you do use it, I recommend not setting it to a hard coded value like 5. Since it's an 'enum' the recommended way to doing it is to use POPUP_BUTTONS_NO_BUTTONS. I would suggest using the call rather than the parameter.

Was this page helpful?
0 / 5 - 0 ratings