Gtk.Expander

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Bin Gtk.Bin Gtk.Expander Gtk.Expander Gtk.Bin->Gtk.Expander Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.Container->Gtk.Bin Gtk.Widget->Gtk.Container

Subclasses:None

Methods

Inherited:Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)
Structs:Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)
class new (label)
class new_with_mnemonic (label)
  get_expanded ()
  get_label ()
  get_label_fill ()
  get_label_widget ()
  get_resize_toplevel ()
  get_spacing ()
  get_use_markup ()
  get_use_underline ()
  set_expanded (expanded)
  set_label (label)
  set_label_fill (label_fill)
  set_label_widget (label_widget)
  set_resize_toplevel (resize_toplevel)
  set_spacing (spacing)
  set_use_markup (use_markup)
  set_use_underline (use_underline)

Properties

Inherited:Gtk.Container (3), Gtk.Widget (39)
Name Type Flags Short Description
expanded bool r/w/c/en Whether the expander has been opened to reveal the child widget
label str r/w/c Text of the expander’s label
label-fill bool r/w/c/en Whether the label widget should fill all available horizontal space
label-widget Gtk.Widget r/w A widget to display in place of the usual expander label
resize-toplevel bool r/w/en Whether the expander will resize the toplevel window upon expanding and collapsing
spacing int d/r/w/en Space to put between the label and the child deprecated
use-markup bool r/w/c/en The text of the label includes XML markup. See Pango.parse_markup()
use-underline bool r/w/c/en If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key

Style Properties

Inherited:Gtk.Widget (17)
Name Type Default Flags Short Description
expander-size int 10 d/r Size of the expander arrow deprecated
expander-spacing int 2 d/r Spacing around expander arrow deprecated

Signals

Inherited:Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)
Name Short Description
activate  

Fields

Inherited:Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)
Name Type Access Description
bin Gtk.Bin r  
priv Gtk.ExpanderPrivate r  

Class Details

class Gtk.Expander(**kwargs)
Bases:Gtk.Bin
Abstract:No
Structure:Gtk.ExpanderClass

A Gtk.Expander allows the user to hide or show its child by clicking on an expander triangle similar to the triangles used in a Gtk.TreeView.

Normally you use an expander as you would use any other descendant of Gtk.Bin; you create the child widget and use Gtk.Container.add() to add it to the expander. When the expander is toggled, it will take care of showing and hiding the child automatically.

Special Usage

There are situations in which you may prefer to show and hide the expanded widget yourself, such as when you want to actually create the widget at expansion time. In this case, create a Gtk.Expander but do not add a child to it. The expander widget has an Gtk.Expander :expanded property which can be used to monitor its expansion state. You should watch this property with a signal connection as follows:

static void
expander_callback (GObject    *object,
                   GParamSpec *param_spec,
                   gpointer    user_data)
{
  GtkExpander *expander;

  expander = GTK_EXPANDER (object);

  if (gtk_expander_get_expanded (expander))
    {
      // Show or create widgets
    }
  else
    {
      // Hide or destroy widgets
    }
}

static void
create_expander (void)
{
  GtkWidget *expander = gtk_expander_new_with_mnemonic ("_More Options");
  g_signal_connect (expander, "notify::expanded",
                    G_CALLBACK (expander_callback), NULL);

  // ...
}
Gtk.Expander as Gtk.Buildable

The Gtk.Expander implementation of the Gtk.Buildable interface supports placing a child in the label position by specifying “label” as the “type” attribute of a <child> element. A normal content child can be specified without specifying a <child> type attribute.

An example of a UI definition fragment with Gtk.Expander:

<object class="GtkExpander">
  <child type="label">
    <object class="GtkLabel" id="expander-label"/>
  </child>
  <child>
    <object class="GtkEntry" id="expander-content"/>
  </child>
</object>
CSS nodes
expander
├── title
│   ├── arrow
│   ╰── <label widget>
╰── <child>

Gtk.Expander has three CSS nodes, the main node with the name expander, a subnode with name title and node below it with name arrow. The arrow of an expander that is showing its child gets the :checked pseudoclass added to it.

classmethod new(label)[source]
Parameters:label (str or None) – the text of the label
Returns:a new Gtk.Expander widget.
Return type:Gtk.Widget

Creates a new expander using label as the text of the label.

New in version 2.4.

classmethod new_with_mnemonic(label)[source]
Parameters:label (str or None) – the text of the label with an underscore in front of the mnemonic character
Returns:a new Gtk.Expander widget.
Return type:Gtk.Widget

Creates a new expander using label as the text of the label. If characters in label are preceded by an underscore, they are underlined. If you need a literal underscore character in a label, use “__” (two underscores). The first underlined character represents a keyboard accelerator called a mnemonic. Pressing Alt and that key activates the button.

New in version 2.4.

get_expanded()[source]
Returns:the current state of the expander
Return type:bool

Queries a Gtk.Expander and returns its current state. Returns True if the child widget is revealed.

See Gtk.Expander.set_expanded().

New in version 2.4.

get_label()[source]
Returns:The text of the label widget. This string is owned by the widget and must not be modified or freed.
Return type:str or None

Fetches the text from a label widget including any embedded underlines indicating mnemonics and Pango markup, as set by Gtk.Expander.set_label(). If the label text has not been set the return value will be None. This will be the case if you create an empty button with Gtk.Button.new() to use as a container.

Note that this function behaved differently in versions prior to 2.14 and used to return the label text stripped of embedded underlines indicating mnemonics and Pango markup. This problem can be avoided by fetching the label text directly from the label widget.

New in version 2.4.

get_label_fill()[source]
Returns:True if the label widget will fill all available horizontal space
Return type:bool

Returns whether the label widget will fill all available horizontal space allocated to self.

New in version 2.22.

get_label_widget()[source]
Returns:the label widget, or None if there is none
Return type:Gtk.Widget or None

Retrieves the label widget for the frame. See Gtk.Expander.set_label_widget().

New in version 2.4.

get_resize_toplevel()[source]
Returns:the “resize toplevel” setting.
Return type:bool

Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collpasing.

New in version 3.2.

get_spacing()[source]
Returns:spacing between the expander and child
Return type:int

Gets the value set by Gtk.Expander.set_spacing().

New in version 2.4.

Deprecated since version 3.20: Use margins on the child instead.

get_use_markup()[source]
Returns:True if the label’s text will be parsed for markup
Return type:bool

Returns whether the label’s text is interpreted as marked up with the Pango text markup language. See Gtk.Expander.set_use_markup().

New in version 2.4.

get_use_underline()[source]
Returns:True if an embedded underline in the expander label indicates the mnemonic accelerator keys
Return type:bool

Returns whether an embedded underline in the expander label indicates a mnemonic. See Gtk.Expander.set_use_underline().

New in version 2.4.

set_expanded(expanded)[source]
Parameters:expanded (bool) – whether the child widget is revealed

Sets the state of the expander. Set to True, if you want the child widget to be revealed, and False if you want the child widget to be hidden.

New in version 2.4.

set_label(label)[source]
Parameters:label (str or None) – a string

Sets the text of the label of the expander to label.

This will also clear any previously set labels.

New in version 2.4.

set_label_fill(label_fill)[source]
Parameters:label_fill (bool) – True if the label should should fill all available horizontal space

Sets whether the label widget should fill all available horizontal space allocated to self.

New in version 2.22.

set_label_widget(label_widget)[source]
Parameters:label_widget (Gtk.Widget or None) – the new label widget

Set the label widget for the expander. This is the widget that will appear embedded alongside the expander arrow.

New in version 2.4.

set_resize_toplevel(resize_toplevel)[source]
Parameters:resize_toplevel (bool) – whether to resize the toplevel

Sets whether the expander will resize the toplevel widget containing the expander upon resizing and collpasing.

New in version 3.2.

set_spacing(spacing)[source]
Parameters:spacing (int) – distance between the expander and child in pixels

Sets the spacing field of self, which is the number of pixels to place between expander and the child.

New in version 2.4.

Deprecated since version 3.20: Use margins on the child instead.

set_use_markup(use_markup)[source]
Parameters:use_markup (bool) – True if the label’s text should be parsed for markup

Sets whether the text of the label contains markup in Pango’s text markup language. See Gtk.Label.set_markup().

New in version 2.4.

set_use_underline(use_underline)[source]
Parameters:use_underline (bool) – True if underlines in the text indicate mnemonics

If true, an underline in the text of the expander label indicates the next character should be used for the mnemonic accelerator key.

New in version 2.4.

do_activate() virtual

Signal Details

Gtk.Expander.signals.activate(expander)
Signal Name:activate
Flags:RUN_LAST, ACTION
Parameters:expander (Gtk.Expander) – The object which received the signal

Property Details

Gtk.Expander.props.expanded
Name:expanded
Type:bool
Default Value:False
Flags:READABLE, WRITABLE, CONSTRUCT, EXPLICIT_NOTIFY

Whether the expander has been opened to reveal the child widget

Gtk.Expander.props.label
Name:label
Type:str
Default Value:None
Flags:READABLE, WRITABLE, CONSTRUCT

Text of the expander’s label

Gtk.Expander.props.label_fill
Name:label-fill
Type:bool
Default Value:False
Flags:READABLE, WRITABLE, CONSTRUCT, EXPLICIT_NOTIFY

Whether the label widget should fill all available horizontal space

Gtk.Expander.props.label_widget
Name:label-widget
Type:Gtk.Widget
Default Value:None
Flags:READABLE, WRITABLE

A widget to display in place of the usual expander label

Gtk.Expander.props.resize_toplevel
Name:resize-toplevel
Type:bool
Default Value:False
Flags:READABLE, WRITABLE, EXPLICIT_NOTIFY

When this property is True, the expander will resize the toplevel widget containing the expander upon expanding and collapsing.

New in version 3.2.

Gtk.Expander.props.spacing
Name:spacing
Type:int
Default Value:0
Flags:DEPRECATED, READABLE, WRITABLE, EXPLICIT_NOTIFY

Space to put between the label and the child when the expander is expanded.

Deprecated since version 3.20: This property is deprecated and ignored. Use margins on the child instead.

Gtk.Expander.props.use_markup
Name:use-markup
Type:bool
Default Value:False
Flags:READABLE, WRITABLE, CONSTRUCT, EXPLICIT_NOTIFY

The text of the label includes XML markup. See Pango.parse_markup()

Gtk.Expander.props.use_underline
Name:use-underline
Type:bool
Default Value:False
Flags:READABLE, WRITABLE, CONSTRUCT, EXPLICIT_NOTIFY

If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key