gtk.button

Module for [Button] class

Types 3

The [gtk.button.Button] widget is generally used to trigger a callback function that is called when the button is pressed.

!An example GtkButton

The [gtk.button.Button] widget can hold any valid child widget. That is, it can hold almost any other standard [gtk.widget.Widget]. The most commonly used child is the [gtk.label.Label].

CSS nodes

[gtk.button.Button] 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 [gtk.button.Button] include .suggested-action and .destructive-action. In special cases, buttons can be made round by adding the .circular style class.

Button-like widgets like [gtk.toggle_button.ToggleButton], [gtk.menu_button.MenuButton], [gtk.volume_button.VolumeButton], [gtk.lock_button.LockButton], [gtk.color_button.ColorButton] or [gtk.font_button.FontButton] use style classes such as .toggle, .popup, .scale, .lock, .color on the button node to differentiate themselves from a plain [gtk.button.Button].

Accessibility

[gtk.button.Button] uses the [gtk.types.AccessibleRole.Button] role.

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 canShrink() @propertyGet `canShrink` property. Returns: Whether the size of the button can be made smaller than the natural size of its contents.
void canShrink(bool propval) @propertySet `canShrink` property. Params: propval = Whether the size of the button can be made smaller than the natural size of its contents.
gtk.widget.Widget child() @propertyGet `child` property. Returns: The child widget.
void child(gtk.widget.Widget propval) @propertySet `child` property. Params: propval = The child widget.
bool hasFrame() @propertyGet `hasFrame` property. Returns: Whether the button has a frame.
void hasFrame(bool propval) @propertySet `hasFrame` property. Params: propval = Whether the button has a frame.
string iconName() @propertyGet `iconName` property. Returns: The name of the icon used to automatically populate the button.
void iconName(string propval) @propertySet `iconName` property. Params: propval = The name of the icon used to automatically populate the button.
string label() @propertyGet `label` property. Returns: Text of the label inside the button, if the button contains a label widget.
void label(string propval) @propertySet `label` property. Params: propval = Text of the label inside the button, if the button contains a label widget.
bool useUnderline() @propertyGet `useUnderline` property. Returns: If set, an underline in the text indicates that the following character is to be used as mnemonic.
void useUnderline(bool propval) @propertySet `useUnderline` property. Params: propval = If set, an underline in the text indicates that the following character is to be used as mnemonic.
gtk.button.Button newFromIconName(string iconName)Creates a new button containing an icon from the current icon theme.
gtk.button.Button newWithLabel(string label)Creates a [gtk.button.Button] widget with a [gtk.label.Label] child.
gtk.button.Button newWithMnemonic(string label)Creates a new [gtk.button.Button] containing a label.
bool getCanShrink()Retrieves whether the button can be smaller than the natural size of its contents. Returns: true if the button can shrink, and false otherwise
gtk.widget.Widget getChild()Gets the child widget of button. Returns: the child widget of button
bool getHasFrame()Returns whether the button has a frame. Returns: true if the button has a frame
string getIconName()Returns the icon name of the button.
string getLabel()Fetches the text from the label of the button.
bool getUseUnderline()gets whether underlines are interpreted as mnemonics.
void setCanShrink(bool canShrink)Sets whether the button size can be smaller than the natural size of its contents.
void setChild(gtk.widget.Widget child = null)Sets the child widget of button.
void setHasFrame(bool hasFrame)Sets the style of the button.
void setIconName(string iconName)Adds a [gtk.image.Image] with the given icon name as a child.
void setLabel(string label)Sets the text of the label of the button to label.
void setUseUnderline(bool useUnderline)Sets whether to use underlines as mnemonics.
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.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new [gtk.button.Button] widget.
Methods
T canShrink(bool propval)Set `canShrink` property. Params: propval = Whether the size of the button can be made smaller than the natural size of its contents.
T child(gtk.widget.Widget propval)Set `child` property. Params: propval = The child widget. Returns: Builder instance for fluent chaining
T hasFrame(bool propval)Set `hasFrame` property. Params: propval = Whether the button has a frame. Returns: Builder instance for fluent chaining
T iconName(string propval)Set `iconName` property. Params: propval = The name of the icon used to automatically populate the button. Returns: Builder instance for fluent chaining
T label(string propval)Set `label` property. Params: propval = Text of the label inside the button, if the button contains a label widget. Returns: Builder instance for fluent chaining
T useUnderline(bool propval)Set `useUnderline` property. Params: propval = If set, an underline in the text indicates that the following character is to be used as mnemonic. Returns: Builder instance for fluent chaining

Fluent builder for [gtk.button.Button]

Methods