AlertDialog#

Added in version 4.10.

class AlertDialog(**properties: Any)#

Superclasses: Object

Collects the arguments that are needed to present a message to the user.

The message is shown with the choose function.

If you don’t need to wait for a button to be clicked, you can use show.

Methods#

class AlertDialog
async choose(self, parent: Window | None = None) int#

This is the awaitable version of choose().

Added in version 4.10.

Parameters:

parent – the parent window

choose(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Shows the alert to the user.

It is ok to pass NULL for the callback if the alert does not have more than one button. A simpler API for this case is show.

Added in version 4.10.

Parameters:
  • parent – the parent window

  • cancellable – a cancellable to cancel the operation

  • callback – a callback to call when the operation is complete

  • user_data – data to pass to callback

choose_finish(result: AsyncResult) int#

Finishes the choose call.

Added in version 4.10.

Parameters:

result – the result

get_buttons() list[str] | None#

Returns the button labels for the alert.

Added in version 4.10.

get_cancel_button() int#

Returns the index of the cancel button.

Added in version 4.10.

get_default_button() int#

Returns the index of the default button.

Added in version 4.10.

get_detail() str#

Returns the detail text that will be shown in the alert.

Added in version 4.10.

get_message() str#

Returns the message that will be shown in the alert.

Added in version 4.10.

get_modal() bool#

Returns whether the alert blocks interaction with the parent window while it is presented.

Added in version 4.10.

set_buttons(labels: list[str]) None#

Sets the button labels for the alert.

Added in version 4.10.

Parameters:

labels – the new button labels

set_cancel_button(button: int) None#

Sets the index of the cancel button.

See cancel_button for details of how this value is used.

Added in version 4.10.

Parameters:

button – the new cancel button

set_default_button(button: int) None#

Sets the index of the default button.

See default_button for details of how this value is used.

Added in version 4.10.

Parameters:

button – the new default button

set_detail(detail: str) None#

Sets the detail text that will be shown in the alert.

Added in version 4.10.

Parameters:

detail – the new detail text

set_message(message: str) None#

Sets the message that will be shown in the alert.

Added in version 4.10.

Parameters:

message – the new message

set_modal(modal: bool) None#

Sets whether the alert blocks interaction with the parent window while it is presented.

Added in version 4.10.

Parameters:

modal – the new value

show(parent: Window | None = None) None#

Shows the alert to the user.

This function is a simpler version of choose intended for dialogs with a single button.

If you want to cancel the dialog or if the alert has more than one button, you should use that function instead and provide it with a Cancellable and callback respectively.

Added in version 4.10.

Parameters:

parent – the parent window

Properties#

class AlertDialog
props.buttons: list[str]#

Labels for buttons to show in the alert.

The labels should be translated and may contain a _ character to indicate the mnemonic character.

If this property is not set, then a ‘Close’ button is automatically created.

Added in version 4.10.

props.cancel_button: int#

Determines what happens when the Escape key is pressed while the alert is shown.

If this property holds the index of a button in buttons, then pressing Escape is treated as if that button was pressed. If it is -1 or not a valid index for the buttons array, then an error is returned.

If buttons is NULL, then the automatically created ‘Close’ button is treated as both cancel and default button, so 0 is returned.

Added in version 4.10.

props.default_button: int#

Determines what happens when the Return key is pressed while the alert is shown.

If this property holds the index of a button in buttons, then pressing Return is treated as if that button was pressed. If it is -1 or not a valid index for the buttons array, then nothing happens.

If buttons is NULL, then the automatically created ‘Close’ button is treated as both cancel and default button, so 0 is returned.

Added in version 4.10.

props.detail: str#

The detail text for the alert.

Added in version 4.10.

props.message: str#

The message for the alert.

Added in version 4.10.

props.modal: bool#

Whether the alert is modal.

Added in version 4.10.