Gtk.Expander


Gtk.Expander — A container which can hide its child

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Bin
                    ╰── Gtk.Expander

Functions:


Signals:

  • “activate” (expander, user_data)

Description:

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 its expansion state. You should watch this property with a signal connection as follows:

        expander = Gtk.Expander(label="Expander")
        expander.connect("activate", self.on_expanded_change)

    def on_expanded_change(self, widget):
        print(widget.get_expanded())

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>

Function Details:

new()

new (label:str) -> Gtk.Widget

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

  • Returns: a new Gtk.Expander widget.

  • Since: 2.4


new_with_mnemonic()

new_with_mnemonic (label:str=None) -> 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 “__” (twounderscores). The first underlined character represents a keyboardaccelerator called a mnemonic.Pressing Alt and that key activates the button.

  • Returns: a new Gtk.Expander widget.

  • Since: 2.4


set_expanded()

set_expanded (self, expanded:bool)

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

  • Since: 2.4

get_expanded()

get_expanded (self) -> bool

Queries a Gtk.Expander and returns its current state. Returns Trueif the child widget is revealed. See Gtk.Expander:set_expanded().

  • Returns: the current state of the expander

  • Since: 2.4


set_spacing()

set_spacing (self, spacing:int)

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

  • Since: 2.4

get_spacing()

get_spacing (self) -> int

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

  • Returns: spacing between the expander and child

  • Since: 2.4


set_label()

set_label (self, label:str=None)

Sets the text of the label of the expander to label. This will also clear any previously set labels.

  • Since: 2.4

get_label()

get_label (self) -> str

Fetches the text from a label widget including any embeddedunderlines indicating mnemonics and Pango markup, as set byGtk.Expander:set_label(). If the label text has not been set thereturn value will be None. This will be the case if you create anempty button with `Gtk.Button:new()` to use as a container. Note that this function behaved differently in versions prior to2.14 and used to return the label text stripped of embeddedunderlines indicating mnemonics and Pango markup. This problem canbe avoided by fetching the label text directly from the labelwidget.

  • Returns: The text of the label widget. This string is ownedby the widget and must not be modified or freed.

  • Since: 2.4


set_use_underline()

set_use_underline (self, use_underline:bool)

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

  • Since: 2.4

get_use_underline()

get_use_underline (self) -> bool

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

  • Returns: True if an embedded underline in the expanderlabel indicates the mnemonic accelerator keys

  • Since: 2.4


set_use_markup()

set_use_markup (self, use_markup:bool)

Sets whether the text of the label contains markup inPango’s text markup language.See `Gtk.Label:set_markup()`.

  • Since: 2.4

get_use_markup()

get_use_markup (self) -> bool

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

  • Returns: True if the label’s text will be parsed for markup

  • Since: 2.4


set_label_widget()

set_label_widget (self, label_widget:Gtk.Widget=None)

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

  • Since: 2.4

get_label_widget()

get_label_widget (self) -> Gtk.Widget

Retrieves the label widget for the frame. SeeGtk.Expander:set_label_widget().

  • Returns: the label widget,or None if there is none.

  • Since: 2.4


set_label_fill()

set_label_fill (self, label_fill:bool)

Sets whether the label widget should fill all availablehorizontal space allocated to expander.

  • Since: 2.22

get_label_fill()

get_label_fill (self) -> bool

Returns whether the label widget will fill all availablehorizontal space allocated to expander.

  • Returns: True if the label widget will fill allavailable horizontal space

  • Since: 2.22


set_resize_toplevel()

set_resize_toplevel (self, resize_toplevel:bool)

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

  • Since: 3.2

get_resize_toplevel()

get_resize_toplevel (self) -> bool

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

  • Returns: the “resize toplevel” setting.

  • Since: 3.2


Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Pango

class Expander(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title("Expander")
        self.set_default_size(300, -1)
        self.connect("destroy", Gtk.main_quit)

        expander = Gtk.Expander(label="Expander")
        expander.set_resize_toplevel(True)
        expander.modify_font(Pango.FontDescription("sans 12"))
        self.add(expander)

        label = Gtk.Label("Label in an Expander")
        label.set_size_request(200, 200)
        expander.add(label)

window = Expander()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""