Next: , Previous: GtkStatusIcon, Up: Top


15 GtkButton

A widget that creates a signal when clicked on

15.1 Overview

The <gtk-button> widget is generally used to attach a function to that is called when the button is pressed. The various signals and how to use them are outlined below.

The <gtk-button> widget can hold any valid child widget. That is it can hold most any other standard <gtk-widget>. The most commonly used child is the <gtk-label>.

15.2 Usage

— Class: <gtk-button>

Derives from <gtk-bin>.

This class defines the following slots:

label
Text of the label widget inside the button, if the button contains a label widget
image
Child widget to appear next to the button text
relief
The border relief style
use-underline
If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key
use-stock
If set, the label is used to pick a stock item instead of being displayed
focus-on-click
Whether the button grabs focus when it is clicked with the mouse
xalign
Horizontal position of child in available space. 0.0 is left aligned, 1.0 is right aligned
yalign
Vertical position of child in available space. 0.0 is top aligned, 1.0 is bottom aligned
image-position
The position of the image relative to the text
— Signal on <gtk-button>: activate

The "activate" signal on GtkButton is an action signal and emitting it causes the button to animate press then release. Applications should never connect to this signal, but use the "clicked" signal.

— Signal on <gtk-button>: pressed

Emitted when the button is pressed.

deprecated: Use the GtkWidget::button-press-event signal.

— Signal on <gtk-button>: released

Emitted when the button is released.

deprecated: Use the GtkWidget::button-release-event signal.

— Signal on <gtk-button>: clicked

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

— Signal on <gtk-button>: enter

Emitted when the pointer enters the button.

deprecated: Use the GtkWidget::enter-notify-event signal.

— Signal on <gtk-button>: leave

Emitted when the pointer leaves the button.

deprecated: Use the GtkWidget::leave-notify-event signal.

— Function: gtk-button-new ⇒  (ret <gtk-widget>)

Creates a new <gtk-button> widget. To add a child widget to the button, use gtk-container-add.

ret
The newly created <gtk-button> widget.
— Function: gtk-button-new-with-label (label mchars) ⇒  (ret <gtk-widget>)

Creates a <gtk-button> widget with a <gtk-label> child containing the given text.

label
The text you want the <gtk-label> to hold.
ret
The newly created <gtk-button> widget.
— Function: gtk-button-new-with-mnemonic (label mchars) ⇒  (ret <gtk-widget>)

Creates a new <gtk-button> 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
The text of the button, with an underscore in front of the mnemonic character
ret
a new <gtk-button>
— Function: gtk-button-new-from-stock (stock_id mchars) ⇒  (ret <gtk-widget>)

Creates a new <gtk-button> containing the image and text from a stock item. Some stock ids have preprocessor macros like <gtk-stock-ok> and <gtk-stock-apply>.

If stock-id is unknown, then it will be treated as a mnemonic label (as for gtk-button-new-with-mnemonic).

stock-id
the name of the stock item
ret
a new <gtk-button>
— Function: gtk-button-pressed (self <gtk-button>)
— Method: pressed

Emits a <gtk-button::pressed> signal to the given <gtk-button>.

button
The <gtk-button> you want to send the signal to.
— Function: gtk-button-released (self <gtk-button>)
— Method: released

Emits a <gtk-button::released> signal to the given <gtk-button>.

button
The <gtk-button> you want to send the signal to.
— Function: gtk-button-clicked (self <gtk-button>)
— Method: clicked

Emits a <gtk-button::clicked> signal to the given <gtk-button>.

button
The <gtk-button> you want to send the signal to.
— Function: gtk-button-enter (self <gtk-button>)
— Method: enter

Emits a <gtk-button::enter> signal to the given <gtk-button>.

button
The <gtk-button> you want to send the signal to.
— Function: gtk-button-leave (self <gtk-button>)
— Method: leave

Emits a <gtk-button::leave> signal to the given <gtk-button>.

button
The <gtk-button> you want to send the signal to.
— Function: gtk-button-set-relief (self <gtk-button>) (newstyle <gtk-relief-style>)
— Method: set-relief

Sets the relief style of the edges of the given <gtk-button> widget. Three styles exist, GTK_RELIEF_NORMAL, GTK_RELIEF_HALF, GTK_RELIEF_NONE. The default style is, as one can guess, GTK_RELIEF_NORMAL.

button
The <gtk-button> you want to set relief styles of.
newstyle
The GtkReliefStyle as described above.
— Function: gtk-button-get-relief (self <gtk-button>) ⇒  (ret <gtk-relief-style>)
— Method: get-relief

Returns the current relief style of the given <gtk-button>.

button
The <gtk-button> you want the <gtk-relief-style> from.
ret
The current <gtk-relief-style>
— Function: gtk-button-get-label (self <gtk-button>) ⇒  (ret mchars)
— Method: get-label

Fetches the text from the label of the button, as set by gtk-button-set-label. If the label text has not been set the return value will be ‘#f’. This will be the case if you create an empty button with gtk-button-new to use as a container.

button
a <gtk-button>
ret
The text of the label widget. This string is owned by the widget and must not be modified or freed.
— Function: gtk-button-set-label (self <gtk-button>) (label mchars)
— Method: set-label

Sets the text of the label of the button to str. This text is also used to select the stock item if gtk-button-set-use-stock is used.

This will also clear any previously set labels.

button
a <gtk-button>
label
a string
— Function: gtk-button-get-use-stock (self <gtk-button>) ⇒  (ret bool)
— Method: get-use-stock

Returns whether the button label is a stock item.

button
a <gtk-button>
ret
#t’ if the button label is used to select a stock item instead of being used directly as the label text.
— Function: gtk-button-set-use-stock (self <gtk-button>) (use_stock bool)
— Method: set-use-stock

If true, the label set on the button is used as a stock id to select the stock item for the button.

button
a <gtk-button>
use-stock
#t’ if the button should use a stock item
— Function: gtk-button-get-use-underline (self <gtk-button>) ⇒  (ret bool)
— Method: get-use-underline

Returns whether an embedded underline in the button label indicates a mnemonic. See gtk-button-set-use-underline.

button
a <gtk-button>
ret
#t’ if an embedded underline in the button label indicates the mnemonic accelerator keys.
— Function: gtk-button-set-use-underline (self <gtk-button>) (use_underline bool)
— Method: set-use-underline

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

button
a <gtk-button>
use-underline
#t’ if underlines in the text indicate mnemonics
— Function: gtk-button-set-focus-on-click (self <gtk-button>) (focus_on_click bool)
— Method: set-focus-on-click

Sets whether the button will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don't want the keyboard focus removed from the main area of the application.

button
a <gtk-button>
focus-on-click
whether the button grabs focus when clicked with the mouse

Since 2.4

— Function: gtk-button-get-focus-on-click (self <gtk-button>) ⇒  (ret bool)
— Method: get-focus-on-click

Returns whether the button grabs focus when it is clicked with the mouse. See gtk-button-set-focus-on-click.

button
a <gtk-button>
ret
#t’ if the button grabs focus when it is clicked with the mouse.

Since 2.4

— Function: gtk-button-set-alignment (self <gtk-button>) (xalign float) (yalign float)
— Method: set-alignment

Sets the alignment of the child. This property has no effect unless the child is a <gtk-misc> or a <gtk-aligment>.

button
a <gtk-button>
xalign
the horizontal position of the child, 0.0 is left aligned, 1.0 is right aligned
yalign
the vertical position of the child, 0.0 is top aligned, 1.0 is bottom aligned

Since 2.4

— Function: gtk-button-get-alignment (self <gtk-button>) ⇒  (xalign float) (yalign float)
— Method: get-alignment

Gets the alignment of the child in the button.

button
a <gtk-button>
xalign
return location for horizontal alignment
yalign
return location for vertical alignment

Since 2.4

— Function: gtk-button-set-image (self <gtk-button>) (image <gtk-widget>)
— Method: set-image

Set the image of button to the given widget. Note that it depends on the gtk-button-images setting whether the image will be displayed or not, you don't have to call gtk-widget-show on image yourself.

button
a <gtk-button>
image
a widget to set as the image for the button

Since 2.6

— Function: gtk-button-get-image (self <gtk-button>) ⇒  (ret <gtk-widget>)
— Method: get-image

Gets the widget that is currenty set as the image of button. This may have been explicitly set by gtk-button-set-image or constructed by gtk-button-new-from-stock.

button
a <gtk-button>
ret
a <gtk-widget> or ‘#f’ in case there is no image

Since 2.6

— Function: gtk-button-set-image-position (self <gtk-button>) (position <gtk-position-type>)
— Method: set-image-position

Sets the position of the image relative to the text inside the button.

button
a <gtk-button>
position
the position

Since 2.10

— Function: gtk-button-get-image-position (self <gtk-button>) ⇒  (ret <gtk-position-type>)
— Method: get-image-position

Gets the position of the image relative to the text inside the button.

button
a <gtk-button>
ret
the position

Since 2.10