Button

    Inherited By: CheckBox, , ColorPickerButton, , OptionButton,

    Standard themed Button.

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

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

    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.

    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 for buttons that trigger gameplay movement or actions, as TouchScreenButton supports multitouch.

    Tutorials

    Theme Properties

    Color

    Color( 0.88, 0.88, 0.88, 1 )

    Color

    Color( 0.9, 0.9, 0.9, 0.2 )

    Color

    Color( 0.94, 0.94, 0.94, 1 )

    Color

    Color( 0.94, 0.94, 0.94, 1 )

    Color

    Color( 1, 1, 1, 1 )

    hseparation

    2

    font

    disabled

    focus

    hover

    normal

    pressed

    enum TextAlign:

    • ALIGN_CENTER = 1 —- Align the text to the center.

    • ALIGN_RIGHT = 2 —- Align the text to the right.

    Property Descriptions

    • align

    Default

    1

    Setter

    set_text_align(value)

    Getter

    get_text_align()

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


    • clip_text

    Default

    Setter

    set_clip_text(value)

    Getter

    get_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.


    Default

    false

    Setter

    set_expand_icon(value)

    Getter

    is_expand_icon()

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


    • flat

    Flat buttons don’t display decoration.


    Setter

    set_button_icon(value)

    Getter

    get_button_icon()

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

    To edit margin and spacing of the icon, use hseparation theme property of Button and content_margin_* properties of the used es.


    Default

    0

    Setter

    set_icon_align(value)

    Getter

    get_icon_align()

    Specifies if the icon should be aligned to the left, right, or center of a button. Uses the same constants as the text alignment. If centered, text will draw on top of the icon.


    Default

    “”

    Setter

    set_text(value)

    Getter

    get_text()

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

    Default

    Color( 0.88, 0.88, 0.88, 1 )

    Default text Color of the Button.


    • font_color_disabled

    Text Color used when the Button is disabled.


    • font_color_focus

    Default

    Color( 0.94, 0.94, 0.94, 1 )

    Text Color used when the is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.


    • font_color_hover

    Default

    Color( 0.94, 0.94, 0.94, 1 )

    Text Color used when the Button is being hovered.


    • font_color_pressed

    Default

    Color( 1, 1, 1, 1 )

    Text Color used when the Button is being pressed.


    • hseparation

    Default

    2

    The horizontal space between Button‘s icon and text.


    of the Button‘s text.


    used when the Button is disabled.


    used when the Button is focused. It is displayed over the current StyleBox, so using will just disable the focus visual effect.


    used when the Button is being hovered.


    Default StyleBox for the Button.


    • pressed