Skip to content

Gtk.InfoBar

class — extends Widget, Accessible, Buildable, ConstraintTarget

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

GtkInfoBar can be used to show messages to the user without a dialog.

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

It is often temporarily shown at the top or bottom of a document. In contrast to Dialog, which has an action area at the bottom, GtkInfoBar has an action area at the side.

The API of GtkInfoBar is very similar to GtkDialog, allowing you to add buttons to the action area with InfoBar.add_button or InfoBar.new_with_buttons. The sensitivity of action widgets can be controlled with InfoBar.set_response_sensitive.

To add widgets to the main content area of a GtkInfoBar, use InfoBar.add_child.

Similar to MessageDialog, the contents of a GtkInfoBar can by classified as error message, warning, informational message, etc, by using InfoBar.set_message_type. GTK may use the message type to determine how the message is displayed.

A simple example for using a GtkInfoBar:

GtkWidget *message_label;
GtkWidget *widget;
GtkWidget *grid;
GtkInfoBar *bar;

// set up info bar
widget = gtk_info_bar_new ();
bar = GTK_INFO_BAR (widget);
grid = gtk_grid_new ();

message_label = gtk_label_new ("");
gtk_info_bar_add_child (bar, message_label);
gtk_info_bar_add_button (bar,
                         _("_OK"),
                         GTK_RESPONSE_OK);
g_signal_connect (bar,
                  "response",
                  G_CALLBACK (gtk_widget_hide),
                  NULL);
gtk_grid_attach (GTK_GRID (grid),
                 widget,
                 0, 2, 1, 1);

// ...

// show an error message
gtk_label_set_text (GTK_LABEL (message_label), "An error occurred!");
gtk_info_bar_set_message_type (bar, GTK_MESSAGE_ERROR);
gtk_widget_show (bar);

GtkInfoBar as GtkBuildable

GtkInfoBar supports a custom <action-widgets> element, which can contain multiple <action-widget> elements. The “response” attribute specifies a numeric response, and the content of the element is the id of widget (which should be a child of the dialogs action_area).

GtkInfoBar supports adding action widgets by specifying “action” as the “type” attribute of a <child> element. The widget will be added either to the action area. The response id has to be associated with the action widget using the <action-widgets> element.

CSS nodes

GtkInfoBar has a single CSS node with name infobar. The node may get one of the style classes .info, .warning, .error or .question, depending on the message type. If the info bar shows a close button, that button will have the .close style class applied.

Constructors

new

@classmethod
def new(cls) -> Widget

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

Creates a new GtkInfoBar object.

Methods

add_action_widget

def add_action_widget(self, child: Widget, response_id: int) -> None

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

Add an activatable widget to the action area of a GtkInfoBar.

This also connects a signal handler that will emit the InfoBar.response signal on the message area when the widget is activated. The widget is appended to the end of the message areas action area.

Parameters:

  • child — an activatable widget
  • response_id — response ID for child

add_button

def add_button(self, button_text: str, response_id: int) -> Button

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

Adds a button with the given text.

Clicking the button will emit the InfoBar.response signal with the given response_id. The button is appended to the end of the info bar's action area. The button widget is returned, but usually you don't need it.

Parameters:

  • button_text — text of button
  • response_id — response ID for the button

add_child

def add_child(self, widget: Widget) -> None

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

Adds a widget to the content area of the info bar.

Parameters:

  • widget — the child to be added

get_message_type

def get_message_type(self) -> MessageType

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

Returns the message type of the message area.

get_revealed

def get_revealed(self) -> bool

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

Returns whether the info bar is currently revealed.

get_show_close_button

def get_show_close_button(self) -> bool

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

Returns whether the widget will display a standard close button.

remove_action_widget

def remove_action_widget(self, widget: Widget) -> None

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

Removes a widget from the action area of info_bar.

The widget must have been put there by a call to InfoBar.add_action_widget or InfoBar.add_button.

Parameters:

  • widget — an action widget to remove

remove_child

def remove_child(self, widget: Widget) -> None

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

Removes a widget from the content area of the info bar.

Parameters:

  • widget — a child that has been added to the content area

response

def response(self, response_id: int) -> None

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

Emits the “response” signal with the given response_id.

Parameters:

  • response_id — a response ID

set_default_response

def set_default_response(self, response_id: int) -> None

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

Sets the last widget in the info bar’s action area with the given response_id as the default widget for the dialog.

Pressing “Enter” normally activates the default widget.

Note that this function currently requires info_bar to be added to a widget hierarchy.

Parameters:

  • response_id — a response ID

set_message_type

def set_message_type(self, message_type: MessageType | int) -> None

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

Sets the message type of the message area.

GTK uses this type to determine how the message is displayed.

Parameters:

  • message_type — a GtkMessageType

set_response_sensitive

def set_response_sensitive(self, response_id: int, setting: bool) -> None

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

Sets the sensitivity of action widgets for response_id.

Calls gtk_widget_set_sensitive (widget, setting) for each widget in the info bars’s action area with the given response_id. A convenient way to sensitize/desensitize buttons.

Parameters:

  • response_id — a response ID
  • setting — TRUE for sensitive

set_revealed

def set_revealed(self, revealed: bool) -> None

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

Sets whether the GtkInfoBar is revealed.

Changing this will make info_bar reveal or conceal itself via a sliding transition.

Note: this does not show or hide info_bar in the Widget.visible sense, so revealing has no effect if Widget.visible is False.

Parameters:

  • revealed — The new value of the property

set_show_close_button

def set_show_close_button(self, setting: bool) -> None

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

If true, a standard close button is shown.

When clicked it emits the response ResponseType.CLOSE.

Parameters:

  • settingTrue to include a close button

Properties

message_type

message_type: MessageType | int  # read/write

The type of the message.

The type may be used to determine the appearance of the info bar.

revealed

revealed: bool  # read/write

Whether the info bar shows its contents.

show_close_button

show_close_button: bool  # read/write

Whether to include a standard close button.

Signals

close

def on_close(self) -> None: ...

Gets emitted when the user uses a keybinding to dismiss the info bar.

The ::close signal is a keybinding signal.

The default binding for this signal is the Escape key.

response

def on_response(self, response_id: int) -> None: ...

Emitted when an action widget is clicked.

The signal is also emitted when the application programmer calls InfoBar.response. The response_id depends on which action widget was clicked.