Skip to content

Gtk.AlertDialog

class — extends GObject.Object

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

The message is shown with the AlertDialog.choose function.

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

Methods

choose

def choose(self, parent: Window | None = ..., cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | 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 AlertDialog.show.

Parameters:

  • parent — the parent window
  • cancellable — a cancellable to cancel the operation
  • callback — a callback to call when the operation is complete

choose_finish

def choose_finish(self, result: Gio.AsyncResult) -> int

Finishes the AlertDialog.choose call.

Parameters:

  • result — the result

get_buttons

def get_buttons(self) -> list[str] | None

Returns the button labels for the alert.

get_cancel_button

def get_cancel_button(self) -> int

Returns the index of the cancel button.

get_default_button

def get_default_button(self) -> int

Returns the index of the default button.

get_detail

def get_detail(self) -> str

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

get_message

def get_message(self) -> str

Returns the message that will be shown in the alert.

get_modal

def get_modal(self) -> bool

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

set_buttons

def set_buttons(self, labels: list[str]) -> None

Sets the button labels for the alert.

Parameters:

  • labels — the new button labels

set_cancel_button

def set_cancel_button(self, button: int) -> None

Sets the index of the cancel button.

See AlertDialog.cancel-button for details of how this value is used.

Parameters:

  • button — the new cancel button

set_default_button

def set_default_button(self, button: int) -> None

Sets the index of the default button.

See AlertDialog.default-button for details of how this value is used.

Parameters:

  • button — the new default button

set_detail

def set_detail(self, detail: str) -> None

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

Parameters:

  • detail — the new detail text

set_message

def set_message(self, message: str) -> None

Sets the message that will be shown in the alert.

Parameters:

  • message — the new message

set_modal

def set_modal(self, modal: bool) -> None

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

Parameters:

  • modal — the new value

show

def show(self, parent: Window | None = ...) -> None

Shows the alert to the user.

This function is a simpler version of AlertDialog.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 Gio.Cancellable and callback respectively.

Parameters:

  • parent — the parent window

Properties

buttons

buttons: list[str]  # read/write

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.

cancel_button

cancel_button: int  # read/write

Determines what happens when the <kbd>Escape</kbd> key is pressed while the alert is shown.

If this property holds the index of a button in AlertDialog.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.

default_button

default_button: int  # read/write

Determines what happens when the <kbd>Return</kbd> key is pressed while the alert is shown.

If this property holds the index of a button in AlertDialog.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.

detail

detail: str  # read/write

The detail text for the alert.

message

message: str  # read/write

The message for the alert.

modal

modal: bool  # read/write

Whether the alert is modal.