Skip to content

Gtk.MessageDialog

class — extends Dialog, Accessible, Buildable, ConstraintTarget, Native, Root, ShortcutManager

:::warning Deprecated since 4.10 This API is deprecated. :::

GtkMessageDialog presents a dialog with some message text.

<picture> <source srcset="messagedialog-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkMessageDialog" src="messagedialog.png"> </picture>

It’s simply a convenience widget; you could construct the equivalent of GtkMessageDialog from GtkDialog without too much effort, but GtkMessageDialog saves typing.

The easiest way to do a modal message dialog is to use the DialogFlags.MODAL flag, which will call Window.set_modal internally. The dialog will prevent interaction with the parent window until it's hidden or destroyed. You can use the Dialog.response signal to know when the user dismissed the dialog.

An example for using a modal dialog:

GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL;
dialog = gtk_message_dialog_new (parent_window,
                                 flags,
                                 GTK_MESSAGE_ERROR,
                                 GTK_BUTTONS_CLOSE,
                                 "Error reading “%s”: %s",
                                 filename,
                                 g_strerror (errno));
// Destroy the dialog when the user responds to it
// (e.g. clicks a button)

g_signal_connect (dialog, "response",
                  G_CALLBACK (gtk_window_destroy),
                  NULL);

You might do a non-modal GtkMessageDialog simply by omitting the DialogFlags.MODAL flag:

GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
dialog = gtk_message_dialog_new (parent_window,
                                 flags,
                                 GTK_MESSAGE_ERROR,
                                 GTK_BUTTONS_CLOSE,
                                 "Error reading “%s”: %s",
                                 filename,
                                 g_strerror (errno));

// Destroy the dialog when the user responds to it
// (e.g. clicks a button)
g_signal_connect (dialog, "response",
                  G_CALLBACK (gtk_window_destroy),
                  NULL);

GtkMessageDialog as GtkBuildable

The GtkMessageDialog implementation of the GtkBuildable interface exposes the message area as an internal child with the name “message_area”.

Methods

get_message_area

def get_message_area(self) -> Widget

:::warning Deprecated since 4.10 This API is deprecated. :::

Returns the message area of the dialog.

This is the box where the dialog’s primary and secondary labels are packed. You can add your own extra content to that box and it will appear below those labels. See Dialog.get_content_area for the corresponding function in the parent Dialog.

set_markup

def set_markup(self, str: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the text of the message dialog.

Parameters:

  • str — string with Pango markup

Properties

buttons

buttons: ButtonsType | int  # read/write

Set of buttons to display on the dialog.

message_area

message_area: Widget  # read-only

The GtkBox that corresponds to the message area of this dialog.

See MessageDialog.get_message_area for a detailed description of this area.

message_type

message_type: MessageType | int  # read/write

The type of the message.

secondary_text

secondary_text: str  # read/write

The secondary text of the message dialog.

secondary_use_markup

secondary_use_markup: bool  # read/write

True if the secondary text of the dialog includes Pango markup.

See Pango.parse_markup.

text

text: str  # read/write

The primary text of the message dialog.

If the dialog has a secondary text, this will appear as the title.

use_markup

use_markup: bool  # read/write

True if the primary text of the dialog includes Pango markup.

See Pango.parse_markup.