GtkButton: GTK+ 4 Reference Manual

## 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_clicked ()
void | gtk_button_set_relief ()
GtkReliefStyle | gtk_button_get_relief ()
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 ()

## Types and Values

struct | GtkButton
struct | GtkButtonClass

## 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, GtkFontButton or GtkFileChooserButton use style classes such as .toggle, .popup, .scale, .lock, .color, .file 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,
                                   GtkIconSize size);

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]
size | an icon size (GtkIconSize). | [type int]

#### Returns

a new GtkButton displaying the themed icon

Since: 3.10

### gtk_button_clicked ()

    void
    gtk_button_clicked (GtkButton *button);

Emits a “clicked” signal to the given GtkButton.

#### Parameters

button | The GtkButton you want to send the signal to. |

### gtk_button_set_relief ()

    void
    gtk_button_set_relief (GtkButton *button,
                           GtkReliefStyle relief);

Sets the relief style of the edges of the given GtkButton widget. Two styles exist, `GTK_RELIEF_NORMAL` and `GTK_RELIEF_NONE`. The default style is, as one can guess, `GTK_RELIEF_NORMAL`.

#### Parameters

button | The GtkButton you want to set relief styles of |
relief | The GtkReliefStyle as described above |

### gtk_button_get_relief ()

    GtkReliefStyle
    gtk_button_get_relief (GtkButton *button);

Returns the current relief style of the given GtkButton.

#### Parameters

button | The GtkButton you want the GtkReliefStyle from. |

#### Returns

The current GtkReliefStyle

### 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. The icon will be of size `GTK_ICON_SIZE_BUTTON`. If `button` already contains a child widget, that child widget will be removed and replaced with the image.

#### Parameters

button | A GtkButton |
icon_name | A icon name |

Since: 3.90

### 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]

Since: 3.90

## Types and Values

### struct GtkButton

    struct GtkButton {
    };

### struct GtkButtonClass

    struct GtkButtonClass {
      GtkBinClass        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. |