gtk.button

Module for [Button] class

Types 3

The #GtkButton widget is generally used to trigger a callback function that is called when the button is pressed. The various signals and how to use them are outlined below.

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.

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.

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, #GtkFontButton or #GtkFileChooserButton use style classes such as .toggle, .popup, .scale, .lock, .color, .font, .file to differentiate themselves from a plain GtkButton.

Methods
GType _gType() @property
Button self()Returns `this`, for use in `with` statements.
ButtonGidBuilder builder()Get builder for [gtk.button.Button] Returns: New builder object
bool alwaysShowImage() @propertyGet `alwaysShowImage` property. Returns: If true, the button will ignore the #GtkSettings:gtk-button-images setting and always show the image, if available.
void alwaysShowImage(bool propval) @propertySet `alwaysShowImage` property. Params: propval = If true, the button will ignore the #GtkSettings:gtk-button-images setting and always show the image, if available.
gtk.widget.Widget image() @propertyGet `image` property. Returns: The child widget to appear next to the button text.
void image(gtk.widget.Widget propval) @propertySet `image` property. Params: propval = The child widget to appear next to the button text.
gtk.types.PositionType imagePosition() @propertyGet `imagePosition` property. Returns: The position of the image relative to the text inside the button.
void imagePosition(gtk.types.PositionType propval) @propertySet `imagePosition` property. Params: propval = The position of the image relative to the text inside the button.
string label() @property
void label(string propval) @property
void relief(gtk.types.ReliefStyle propval) @property
bool useStock() @property
void useStock(bool propval) @property
bool useUnderline() @property
void useUnderline(bool propval) @property
float xalign() @propertyGet `xalign` property. Returns: If the child of the button is a #GtkMisc or #GtkAlignment, this property can be used to control its horizontal alignment. 0.0 is left aligned, 1.0 is right aligned.
void xalign(float propval) @propertySet `xalign` property. Params: propval = If the child of the button is a #GtkMisc or #GtkAlignment, this property can be used to control its horizontal alignment. 0.0 is left aligned, 1.0 is right ...
float yalign() @propertyGet `yalign` property. Returns: If the child of the button is a #GtkMisc or #GtkAlignment, this property can be used to control its vertical alignment. 0.0 is top aligned, 1.0 is bottom aligned.
void yalign(float propval) @propertySet `yalign` property. Params: propval = If the child of the button is a #GtkMisc or #GtkAlignment, this property can be used to control its vertical alignment. 0.0 is top aligned, 1.0 is bottom al...
gtk.button.Button newFromIconName(string iconName, gtk.types.IconSize size)Creates a new button containing an icon from the current icon theme.
gtk.button.Button newFromStock(string stockId)Creates a new #GtkButton containing the image and text from a [stock item][gtkstock]. Some stock ids have preprocessor macros like #GTKSTOCKOK and #GTKSTOCKAPPLY.
gtk.button.Button newWithLabel(string label)Creates a #GtkButton widget with a #GtkLabel child containing the given text.
gtk.button.Button newWithMnemonic(string label)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 unde...
void clicked()Emits a #GtkButton::clicked signal to the given #GtkButton.
void enter()Emits a #GtkButton::enter signal to the given #GtkButton.
void getAlignment(out float xalign, out float yalign)Gets the alignment of the child in the button.
bool getAlwaysShowImage()Returns whether the button will ignore the #GtkSettings:gtk-button-images setting and always show the image, if available. Returns: true if the button will always show the image
gdk.window.Window getEventWindow()Returns the button’s event window if it is realized, null otherwise. This function should be rarely needed. Returns: button’s event window.
bool getFocusOnClick()Returns whether the button grabs focus when it is clicked with the mouse. See [gtk.button.Button.setFocusOnClick]. Returns: true if the button grabs focus when it is clicked with the mouse.
gtk.widget.Widget getImage()Gets the widget that is currenty set as the image of button. This may have been explicitly set by [gtk.button.Button.setImage] or constructed by [gtk.button.Button.newFromStock]. Returns: a #GtkWid...
gtk.types.PositionType getImagePosition()Gets the position of the image relative to the text inside the button. Returns: the position
string getLabel()Fetches the text from the label of the button, as set by [gtk.button.Button.setLabel]. If the label text has not been set the return value will be null. This will be the case if you create an empty...
gtk.types.ReliefStyle getRelief()Returns the current relief style of the given #GtkButton. Returns: The current #GtkReliefStyle
bool getUseStock()Returns whether the button label is a stock item. Returns: true if the button label is used to select a stock item instead of being used directly as the label text.
bool getUseUnderline()Returns whether an embedded underline in the button label indicates a mnemonic. See gtkbuttonsetuseunderline (). Returns: true if an embedded underline in the button label indicates the mnemonic ac...
void leave()Emits a #GtkButton::leave signal to the given #GtkButton.
void pressed()Emits a #GtkButton::pressed signal to the given #GtkButton.
void released()Emits a #GtkButton::released signal to the given #GtkButton.
void setAlignment(float xalign, float yalign)Sets the alignment of the child. This property has no effect unless the child is a #GtkMisc or a #GtkAlignment.
void setAlwaysShowImage(bool alwaysShow)If true, the button will ignore the #GtkSettings:gtk-button-images setting and always show the image, if available.
void setFocusOnClick(bool focusOnClick)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 fro...
void setImage(gtk.widget.Widget image = null)Set the image of button to the given widget. The image will be displayed if the label text is null or if #GtkButton:always-show-image is true. You don’t have to call [gtk.widget.Widget.show] on i...
void setImagePosition(gtk.types.PositionType position)Sets the position of the image relative to the text inside the button.
void setLabel(string 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.Button.setUseStock] is used.
void setRelief(gtk.types.ReliefStyle relief)Sets the relief style of the edges of the given #GtkButton widget. Two styles exist, [gtk.types.ReliefStyle.Normal] and [gtk.types.ReliefStyle.None]. The default style is, as one can guess, [gtk.ty...
void setUseStock(bool useStock)If true, the label set on the button is used as a stock id to select the stock item for the button.
void setUseUnderline(bool useUnderline)If true, an underline in the text of the button label indicates the next character should be used for the mnemonic accelerator key.
gulong connectActivate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.button.Button))) && Parameters!T.length < 2)Connect to `Activate` signal.
gulong connectClicked(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.button.Button))) && Parameters!T.length < 2)Connect to `Clicked` signal.
gulong connectEnter(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.button.Button))) && Parameters!T.length < 2)Connect to `Enter` signal.
gulong connectLeave(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.button.Button))) && Parameters!T.length < 2)Connect to `Leave` signal.
gulong connectPressed(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.button.Button))) && Parameters!T.length < 2)Connect to `Pressed` signal.
gulong connectReleased(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.button.Button))) && Parameters!T.length < 2)Connect to `Released` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new #GtkButton widget. To add a child widget to the button, use [gtk.container.Container.add]. Returns: The newly created #GtkButton widget.
Methods
T alwaysShowImage(bool propval)Set `alwaysShowImage` property. Params: propval = If true, the button will ignore the #GtkSettings:gtk-button-images setting and always show the image, if available.
T image(gtk.widget.Widget propval)Set `image` property. Params: propval = The child widget to appear next to the button text. Returns: Builder instance for fluent chaining
T imagePosition(gtk.types.PositionType propval)Set `imagePosition` property. Params: propval = The position of the image relative to the text inside the button. Returns: Builder instance for fluent chaining
T label(string propval)
T useStock(bool propval)
T useUnderline(bool propval)
T xalign(float propval)Set `xalign` property. Params: propval = If the child of the button is a #GtkMisc or #GtkAlignment, this property can be used to control its horizontal alignment. 0.0 is left aligned, 1.0 is right ...
T yalign(float propval)Set `yalign` property. Params: propval = If the child of the button is a #GtkMisc or #GtkAlignment, this property can be used to control its vertical alignment. 0.0 is top aligned, 1.0 is bottom al...

Fluent builder for [gtk.button.Button]

Methods