Gtk.Expander

g GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.Expander Gtk.Expander Gtk.Widget->Gtk.Expander

Example

../_images/Expander.png
Subclasses:

None

Methods

Inherited:

Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new (label)

class

new_with_mnemonic (label)

get_child ()

get_expanded ()

get_label ()

get_label_widget ()

get_resize_toplevel ()

get_use_markup ()

get_use_underline ()

set_child (child)

set_expanded (expanded)

set_label (label)

set_label_widget (label_widget)

set_resize_toplevel (resize_toplevel)

set_use_markup (use_markup)

set_use_underline (use_underline)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)

Properties

Inherited:

Gtk.Widget (34), Gtk.Accessible (1)

Name

Type

Flags

Short Description

child

Gtk.Widget

r/w/en

expanded

bool

r/w/c/en

label

str

r/w/c

label-widget

Gtk.Widget

r/w/en

resize-toplevel

bool

r/w/en

use-markup

bool

r/w/c/en

use-underline

bool

r/w/c/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Name

Short Description

activate

Activates the GtkExpander.

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Gtk.Expander(**kwargs)
Bases:

Gtk.Widget

Abstract:

No

GtkExpander allows the user to reveal its child by clicking on an expander triangle.

An example Gtk.Expander

This is similar to the triangles used in a GtkTreeView.

Normally you use an expander as you would use a frame; you create the child widget and use [method`Gtk`.Expander.set_child] 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 GtkExpander but do not add a child to it. The expander widget has an [property`Gtk`.Expander:expanded] property which can be used to monitor its expansion state. You should watch this property with a signal connection as follows:

```c static void expander_callback (GObject.Object *object, GObject.ParamSpec *param_spec, object user_data) { Gtk.Expander *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) { Gtk.Widget *expander = Gtk.Expander.new_with_mnemonic (”_More Options”); g_signal_connect (expander, “notify::expanded”, G_CALLBACK (expander_callback), None);

// … } ```

Gtk.Expander as Gtk.Buildable

The GtkExpander implementation of the GtkBuildable 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:

``xml <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-widget ╰── box

├── title │ ├── expander │ ╰── <label widget> ╰── <child>

``

GtkExpander has a main node expander-widget, and subnode box containing the title and child widget. The box subnode title contains node expander, i.e. the expand/collapse arrow; then the label widget if any. The arrow of an expander that is showing its child gets the :checked pseudoclass set on it.

Accessibility

GtkExpander uses the Gtk.AccessibleRole.BUTTON role.

classmethod new(label)[source]
Parameters:

label (str or None) – the text of the label

Returns:

a new GtkExpander widget.

Return type:

Gtk.Widget

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

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 GtkExpander 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.

get_child()[source]
Returns:

the child widget of self

Return type:

Gtk.Widget or None

Gets the child widget of self.

get_expanded()[source]
Returns:

the current state of the expander

Return type:

bool

Queries a GtkExpander and returns its current state.

Returns True if the child widget is revealed.

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.

This is including any embedded underlines indicating mnemonics and Pango markup, as set by [method`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.

get_label_widget()[source]
Returns:

the label widget

Return type:

Gtk.Widget or None

Retrieves the label widget for the frame.

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 collapsing.

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 Pango markup.

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 underline in the text indicates a mnemonic.

set_child(child)[source]
Parameters:

child (Gtk.Widget or None) – the child widget

Sets the child widget of self.

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.

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.

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.

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 collapsing.

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 Pango markup.

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 indicates a mnemonic.

Signal Details

Gtk.Expander.signals.activate(expander)
Signal Name:

activate

Flags:

RUN_LAST, ACTION

Parameters:

expander (Gtk.Expander) – The object which received the signal

Activates the GtkExpander.

Property Details

Gtk.Expander.props.child
Name:

child

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The child widget.

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.

Gtk.Expander.props.label
Name:

label

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT

The text of the expanders label.

Gtk.Expander.props.label_widget
Name:

label-widget

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

A widget to display instead 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.

Gtk.Expander.props.use_markup
Name:

use-markup

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, CONSTRUCT, EXPLICIT_NOTIFY

Whether the text in the label is Pango markup.

Gtk.Expander.props.use_underline
Name:

use-underline

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, CONSTRUCT, EXPLICIT_NOTIFY

Whether an underline in the text indicates a mnemonic.