## GtkButton GtkButton — A widget that emits a signal when clicked on |

## Functions

GtkWidget * | gtk_button_new ()
GtkWidget * | gtk_button_new_with_label ()
GtkWidget * | gtk_button_new_with_mnemonic ()
GtkWidget * | gtk_button_new_from_icon_name ()
void | gtk_button_set_has_frame ()
gboolean | gtk_button_get_has_frame ()
const gchar * | gtk_button_get_label ()
void | gtk_button_set_label ()
gboolean | gtk_button_get_use_underline ()
void | gtk_button_set_use_underline ()
void | gtk_button_set_icon_name ()
const char * | gtk_button_get_icon_name ()
void | gtk_button_set_child ()
GtkWidget * | gtk_button_get_child ()

## Properties

GtkWidget * | child | Read / Write
gboolean | has-frame | Read / Write
gchar * | icon-name | Read / Write
gchar * | label | Read / Write
gboolean | use-underline | Read / Write

## Signals

void | activate | Action
void | clicked | Action

## Types and Values

struct | GtkButton
struct | GtkButtonClass

## Object Hierarchy

        GObject
        ╰── GInitiallyUnowned
            ╰── GtkWidget
                ╰── GtkButton
                    ├── GtkToggleButton
                    ├── GtkLinkButton
                    ╰── GtkLockButton

## Implemented Interfaces

GtkButton implements AtkImplementorIface, GtkBuildable, GtkConstraintTarget and GtkActionable.

## Includes

    #include <gtk/gtk.h>

## Description

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 or GtkFontButton use style classes such as .toggle, .popup, .scale, .lock, .color on the button node to differentiate themselves from a plain GtkButton.

## Functions

### gtk_button_new ()

    GtkWidget *
    gtk_button_new (void);

Creates a new GtkButton widget. To add a child widget to the button, use `gtk_container_add()`.

#### Returns

The newly created GtkButton widget.

### gtk_button_new_with_label ()

    GtkWidget *
    gtk_button_new_with_label (const gchar *label);

Creates a GtkButton widget with a GtkLabel child containing the given text.

#### Parameters

label | The text you want the GtkLabel to hold. |

#### Returns

The newly created GtkButton widget.

### gtk_button_new_with_mnemonic ()

    GtkWidget *
    gtk_button_new_with_mnemonic (const gchar *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 underscores). The first underlined character represents a keyboard accelerator called a mnemonic. Pressing Alt and that key activates the button.

#### Parameters

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

#### Returns

a new GtkButton

### gtk_button_new_from_icon_name ()

    GtkWidget *
    gtk_button_new_from_icon_name (const gchar *icon_name);

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.

#### Parameters

icon_name | an icon name or `NULL`. | [nullable]

#### Returns

a new GtkButton displaying the themed icon

### gtk_button_set_has_frame ()

    void
    gtk_button_set_has_frame (GtkButton *button,
                              gboolean has_frame);

Sets the style of the button. Buttons can has a flat appearance or have a frame drawn around them.

#### Parameters

button | a GtkButton |
has_frame | whether the button should have a visible frame |

### gtk_button_get_has_frame ()

    gboolean
    gtk_button_get_has_frame (GtkButton *button);

Returns whether the button has a frame.

#### Parameters

button | a GtkButton |

#### Returns

`TRUE` if the button has a frame

### gtk_button_get_label ()

    const gchar *
    gtk_button_get_label (GtkButton *button);

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 `NULL`. This will be the case if you create an empty button with `gtk_button_new()` to use as a container.

#### Parameters

button | a GtkButton |

#### Returns

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

[nullable]

### gtk_button_set_label ()

    void
    gtk_button_set_label (GtkButton *button,
                          const gchar *label);

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

This will also clear any previously set labels.

#### Parameters

button | a GtkButton |
label | a string |

### gtk_button_get_use_underline ()

    gboolean
    gtk_button_get_use_underline (GtkButton *button);

Returns whether an embedded underline in the button label indicates a mnemonic. See `gtk_button_set_use_underline()`.

#### Parameters

button | a GtkButton |

#### Returns

`TRUE` if an embedded underline in the button label indicates the mnemonic accelerator keys.

### gtk_button_set_use_underline ()

    void
    gtk_button_set_use_underline (GtkButton *button,
                                  gboolean 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.

#### Parameters

button | a GtkButton |
use_underline | `TRUE` if underlines in the text indicate mnemonics |

### gtk_button_set_icon_name ()

    void
    gtk_button_set_icon_name (GtkButton *button,
                              const char *icon_name);

Adds a GtkImage with the given icon name as a child. If `button` already contains a child widget, that child widget will be removed and replaced with the image.

#### Parameters

button | A GtkButton |
icon_name | An icon name |

### gtk_button_get_icon_name ()

    const char *
    gtk_button_get_icon_name (GtkButton *button);

Returns the icon name set via `gtk_button_set_icon_name()`.

#### Parameters

button | A GtkButton |

#### Returns

The icon name set via `gtk_button_set_icon_name()`.

[nullable]

### gtk_button_set_child ()

    void
    gtk_button_set_child (GtkButton *button,
                          GtkWidget *child);

Sets the child widget of `button` .

#### Parameters

button | a GtkButton |
child | the child widget. | [allow-none]

### gtk_button_get_child ()

    GtkWidget *
    gtk_button_get_child (GtkButton *button);

Gets the child widget of `button` .

#### Parameters

button | a GtkButton |

#### Returns

the child widget of `button` .

[nullable][transfer none]

## Types and Values

### struct GtkButton

    struct GtkButton;

### struct GtkButtonClass

    struct GtkButtonClass {
      GtkWidgetClass        parent_class;

      void (* clicked)  (GtkButton *button);
      void (* activate) (GtkButton *button);
    };

#### Members

`clicked` () | Signal emitted when the button has been activated (pressed and released). |
`activate` () | Signal that causes the button to animate press then release. Applications should never connect to this signal, but use the `clicked` signal. |

## Property Details

### The `“child”` property

      “child”                    GtkWidget *

The child widget.

Owner: GtkButton

Flags: Read / Write

### The `“has-frame”` property

      “has-frame”                gboolean

Whether the button has a frame.

Owner: GtkButton

Flags: Read / Write

Default value: TRUE

### The `“icon-name”` property

      “icon-name”                gchar *

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

Owner: GtkButton

Flags: Read / Write

Default value: NULL

### The `“label”` property

      “label”                    gchar *

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

Owner: GtkButton

Flags: Read / Write

Default value: NULL

### The `“use-underline”` property

      “use-underline”            gboolean

If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.

Owner: GtkButton

Flags: Read / Write

Default value: FALSE

## Signal Details

### The `“activate”` signal

    void
    user_function (GtkButton *widget,
                   gpointer   user_data)

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.

#### Parameters

widget | the object which received the signal. |
user_data | user data set when the signal handler was connected. |

Flags: Action

### The `“clicked”` signal

    void
    user_function (GtkButton *button,
                   gpointer   user_data)

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

#### Parameters

button | the object that received the signal |
user_data | user data set when the signal handler was connected. |

Flags: Action