Button

Inherits: BaseButton < Control < CanvasItem < Node < Object

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

Standard themed Button.

Description

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

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

  1. func _ready():
  2. var button = Button.new()
  3. button.text = "Click me"
  4. button.connect("pressed", self, "_button_pressed")
  5. add_child(button)
  6. func _button_pressed():
  7. print("Hello world!")

Buttons (like all Control nodes) can also be created in the editor, but some situations may require creating them from code.

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

Tutorials

Properties

TextAlignalign1
boolclip_textfalse
boolexpand_iconfalse
boolflatfalse
Textureicon 
Stringtext“”

Theme Properties

StyleBoxdisabled 
StyleBoxfocus 
Fontfont 
Colorfont_colorColor( 0.88, 0.88, 0.88, 1 )
Colorfont_color_disabledColor( 0.9, 0.9, 0.9, 0.2 )
Colorfont_color_hoverColor( 0.94, 0.94, 0.94, 1 )
Colorfont_color_pressedColor( 1, 1, 1, 1 )
StyleBoxhover 
inthseparation2
StyleBoxnormal 
StyleBoxpressed 

Enumerations

enum TextAlign:

  • ALIGN_LEFT = 0 —- Align the text to the left.
  • ALIGN_CENTER = 1 —- Align the text to the center.
  • ALIGN_RIGHT = 2 —- Align the text to the right.

Property Descriptions

Default1
Setterset_text_align(value)
Getterget_text_align()

Text alignment policy for the button’s text, use one of the TextAlign constants.


Defaultfalse
Setterset_clip_text(value)
Getterget_clip_text()

When this property is enabled, text that is too large to fit the button is clipped, when disabled the Button will always be wide enough to hold the text.


Defaultfalse
Setterset_expand_icon(value)
Getteris_expand_icon()

When enabled, the button’s icon will expand/shrink to fit the button’s size while keeping its aspect.


Defaultfalse
Setterset_flat(value)
Getteris_flat()

Flat buttons don’t display decoration.


Setterset_button_icon(value)
Getterget_button_icon()

Button’s icon, if text is present the icon will be placed before the text.


Default“”
Setterset_text(value)
Getterget_text()

The button’s text that will be displayed inside the button’s area.