1.21 <GtkButton>

Class: <GtkButton>

It derives from <GtkWidget>.

Calls a callback function when the button is clicked.

The <GtkButton> widget can hold any valid child widget. That is, it can hold almost any other standard <GtkWidget>. The most commonly used child is the <GtkLabel>.

Shortcuts and Gestures

The following signals have default keybindings:

CSS nodes

<GtkButton> has a single CSS node with name button. The node will get the style classes .image-button or .text-button, if the content is just an image or label, respectively. It may also receive the .flat style class. When activating a button via the keyboard, the button will temporarily gain the .keyboard-activating style class.

Other style classes that are commonly used with <GtkButton> include .suggested-action and .destructive-action. In special cases, buttons can be made round by adding the .circular style class.

Button-like widgets like <GtkToggleButton>, <GtkMenuButton>, <GtkVolumeButton>, <GtkLockButton>, <GtkColorButton> or <GtkFontButton> use style classes such as .toggle, .popup, .scale, .lock, .color on the button node to differentiate themselves from a plain <GtkButton>.

Accessibility

<GtkButton> uses the Gtk.AccessibleRole.button role.

Properties

Property: button:can-shrink self

Whether the size of the button can be made smaller than the natural size of its contents.

For text buttons, setting this property will allow ellipsizing the label.

If the contents of a button are an icon or a custom widget, setting this property has no effect.

Its value is a boolean.

Set it with (set! (button:can-shrink self) value).

Property: button:child self

The child widget.

Its value is a <GtkWidget>, or #f.

Set it with (set! (button:child self) value).

Property: button:has-frame self

Whether the button has a frame.

Its value is a boolean.

Set it with (set! (button:has-frame self) value).

Property: button:icon-name self

The name of the icon used to automatically populate the button.

Its value is a string, or #f.

Set it with (set! (button:icon-name self) value).

Property: button:label self

Text of the label inside the button, if the button contains a label widget.

Its value is a string, or #f.

Set it with (set! (button:label self) value).

Property: button:use-underline self

If set, an underline in the text indicates that the following character is to be used as mnemonic.

Its value is a boolean.

Set it with (set! (button:use-underline self) value).

Procedures

Method: button:get-can-shrink? self ⇒ %return
Method: get-can-shrink? self ⇒ %return

Retrieves whether the button can be smaller than the natural size of its contents.

self

Passed: a <GtkButton>.

a button

%return

Returned: a boolean.

true if the button can shrink, and false otherwise

Method: button:get-child self ⇒ %return
Method: get-child self ⇒ %return

Gets the child widget of self.

self

Passed: a <GtkButton>.

a <GtkButton>

%return

Returned: a <GtkWidget>, or #f.

the child widget of self

Method: button:get-has-frame? self ⇒ %return
Method: get-has-frame? self ⇒ %return

Returns whether the button has a frame.

self

Passed: a <GtkButton>.

a <GtkButton>

%return

Returned: a boolean.

#t if the button has a frame

Method: button:get-icon-name self ⇒ %return
Method: get-icon-name self ⇒ %return

Returns the icon name of the button.

If the icon name has not been set with button:set-icon-name the return value will be #f. This will be the case if you create an empty button with button:new to use as a container.

self

Passed: a <GtkButton>.

A <GtkButton>

%return

Returned: a string, or #f.

The icon name set via button:set-icon-name

Method: button:get-label self ⇒ %return
Method: get-label self ⇒ %return

Fetches the text from the label of the button.

If the label text has not been set with button:set-label the return value will be #f. This will be the case if you create an empty button with button:new to use as a container.

self

Passed: a <GtkButton>.

a <GtkButton>

%return

Returned: a string, or #f.

The text of the label widget. This string is owned by the widget and must not be modified or freed.

Method: button:get-use-underline? self ⇒ %return
Method: get-use-underline? self ⇒ %return

gets whether underlines are interpreted as mnemonics.

See button:set-use-underline.

self

Passed: a <GtkButton>.

a <GtkButton>

%return

Returned: a boolean.

#t if an embedded underline in the button label indicates the mnemonic accelerator keys.

Procedure: button:new ⇒ %return

Creates a new <GtkButton> widget.

To add a child widget to the button, use button:set-child.

%return

Returned: a <GtkWidget>.

The newly created <GtkButton> widget.

Procedure: button:new-from-icon-name icon-name ⇒ %return

Creates a new button containing an icon from the current icon theme.

If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.

icon-name

Passed: a string.

an icon name

%return

Returned: a <GtkWidget>.

a new <GtkButton> displaying the themed icon

Procedure: button:new-with-label label ⇒ %return

Creates a <GtkButton> widget with a <GtkLabel> child.

label

Passed: a string.

The text you want the <GtkLabel> to hold

%return

Returned: a <GtkWidget>.

The newly created <GtkButton> widget

Procedure: button:new-with-mnemonic label ⇒ %return

Creates a new <GtkButton> containing a 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.

label

Passed: a string.

The text of the button, with an underscore in front of the mnemonic character

%return

Returned: a <GtkWidget>.

a new <GtkButton>

Method: button:set-can-shrink self can-shrink
Method: set-can-shrink self can-shrink

Sets whether the button size can be smaller than the natural size of its contents.

For text buttons, setting can-shrink to true will ellipsize the label.

For icons and custom children, this function has no effect.

self

Passed: a <GtkButton>.

a button

can-shrink

Passed: a boolean.

whether the button can shrink

Method: button:set-child self [child]
Method: set-child self [child]

Sets the child widget of self.

Note that by using this API, you take full responsibility for setting up the proper accessibility label and description information for self. Most likely, you’ll either set the accessibility label or description for self explicitly, or you’ll set a labelled-by or described-by relations from child to self.

self

Passed: a <GtkButton>.

a <GtkButton>

child

Passed, or left out: a <GtkWidget>, or #f.

the child widget

Method: button:set-has-frame self has-frame
Method: set-has-frame self has-frame

Sets the style of the button.

Buttons can have a flat appearance or have a frame drawn around them.

self

Passed: a <GtkButton>.

a <GtkButton>

has-frame

Passed: a boolean.

whether the button should have a visible frame

Method: button:set-icon-name self icon-name
Method: set-icon-name self icon-name

Adds a <GtkImage> with the given icon name as a child.

If self already contains a child widget, that child widget will be removed and replaced with the image.

self

Passed: a <GtkButton>.

A <GtkButton>

icon-name

Passed: a string.

An icon name

Method: button:set-label self label
Method: set-label self label

Sets the text of the label of the button to label.

This will also clear any previously set labels.

self

Passed: a <GtkButton>.

a <GtkButton>

label

Passed: a string.

a string

Method: button:set-use-underline self use-underline
Method: set-use-underline self use-underline

Sets whether to use underlines as mnemonics.

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

self

Passed: a <GtkButton>.

a <GtkButton>

use-underline

Passed: a boolean.

#t if underlines in the text indicate mnemonics

Signals

Signal: button:activate

Connect a handler with (connect object button:activate handler). It is called as (handler self).

Emitted to animate press then release.

This is an action signal. Applications should never connect to this signal, but use the button:clicked signal.

The default bindings for this signal are all forms of the ␣ and Enter keys.

self

Passed: a <GtkButton>.

Signal: button:clicked

Connect a handler with (connect object button:clicked handler). It is called as (handler self).

Emitted when the button has been activated (pressed and released).

self

Passed: a <GtkButton>.

Virtual methods

Virtual method: button:do-activate implementor self

Signal that causes the button to animate press then release. Applications should never connect to this signal, but use the clicked signal.

To override it in a new class, give register-type #:vfuncs `((activate . ,procedure)). The procedure is called as (procedure self).

implementor

Passed: the class whose implementation to call: <GtkButton>, or a class that derives from it, or its GType number.

self

Passed: a <GtkButton>.

Virtual method: button:do-clicked implementor self

Signal emitted when the button has been activated (pressed and released).

To override it in a new class, give register-type #:vfuncs `((clicked . ,procedure)). The procedure is called as (procedure self).

implementor

Passed: the class whose implementation to call: <GtkButton>, or a class that derives from it, or its GType number.

self

Passed: a <GtkButton>.