Fl::Button - Standard Push Button


    use Fl qw[:button];
    my $button = Fl::Button->new(0, 0, 100, 200, 'Hello, World!');
    $button->callback(sub {print q[It's dat boi]} );


Buttons generate callbacks when they are clicked by the user.

You control exactly when and how by changing the values for type() and when(). Buttons can also generate callbacks in response to FL_SHORTCUT events. The button can either have an explicit shortcut($s) value or a letter shortcut can be indicated in the label() with an '&' character before it. For the label shortcut it does not matter if Alt is held down, but if you have an input field in the same window, the user will have to hold down the Alt key so that the input field does not eat the event first as an FL_KEYBOARD event.

Button Types

Setting the buttons's type(...) allows you to define any of the following:


This is a typical button that remains unchanged after the button is pressed.


The value of this button is inverted after it is pressed.


This button is set to 1 after it is pressed and all other buttons in the current group with type() == FL_RADIO_BUTTON are set to zero.

All of the above values may be imported with the :button or :enum tag.

Callback Triggers

For a button, the following when() values are defined:


The callback is not done. Instead, changed() is turned on.


The callback is done after the user successfully clicks the button or when a shortcut is typed.


The callback is done each time the value() changes (when the user pushes and releases the button and as the mouse is dragged around in and out of the button).

All of the above values may be imported with the :when or :enum tag.


Fl::Button inherits from Fl::Widget and exposes the following methods...


    my $button_a = Fl::Button->new(0, 0, 250, 500, 'Important Stuff');
    my $button_b = Fl::Button->new(0, 0, 250, 500);

The constructor creates the button using the given position, size, and label.

You can control how the button is drawn when ON by setting down_box(). The default is FL_NO_BOX which will select an appropriate box type using the normal box type. The default box type is FL_UP_BOX.

The destructor removes the button.



Same as value(0).


    my $boxtype = $button_a->box_down();

Gets or sets the down box type.

The default value causes FLTK to figure out the correct matching down version.



Same as value(1).



Turns this button on and turns off all other radio button sin the group. Note that calling value(1) or set() does not do this.


    my $shortcut = $button_a->shortcut();
    $button_a->shortcut(FL_ALT | 'a');

Sets or returns the current shortcut key for the button.

Setting this overrides the use of '&' in the label(). The value is a bitwise OR of a key and a set of shift flags, for example: FL_ALT | 'a', or FL_ALT | (FL_F + 10), or just 'a'. A value of 0 disables the shortcut.

The key can be any value returned by Fl::event_key(), but will usually be an ASCII letter. Use a lower-case letter unless you require the shift key to be held down.

The shift flags can be any set of values accepted by Fl::event_state(). If the bit is on, that shift key must be pushed. Meta, Alt, Ctrl, and Shift must be off if they are not in the shift flags (zero for the other bits indicates a "don't care" setting).

FL_ALT, FL_F, etc. may be imported with the :keyboard tag.



Sets the current value of the button.

A non-zero value sets the button to 1 (on) and zero sets it to 0 (off).


Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Sanko Robinson <>