Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

Button

Inherits: BaseButton < Control < CanvasItem < Node < Object

Inherited By: CheckBox, CheckButton, ColorPickerButton, MenuButton, OptionButton

A themed button that can contain text and an icon.

Description

Button is the standard themed button. It can contain text and an icon, and it will display them according to the current Theme.

Example of creating a button and assigning an action when pressed by code:

func _ready():
    var button = Button.new()
    button.text = "Click me"
    button.pressed.connect(self._button_pressed)
    add_child(button)

func _button_pressed():
    print("Hello world!")

See also BaseButton which contains common properties and methods associated with this node.

Note: Buttons do not interpret touch input and therefore don't support multitouch, since mouse emulation can only press one button at a given time. Use TouchScreenButton for buttons that trigger gameplay movement or actions.

Tutorials

Properties

HorizontalAlignment

alignment

1

bool

clip_text

false

bool

expand_icon

false

bool

flat

false

Texture2D

icon