Tickit...Button(3pm)
β¨ Tickit::Widget::Button β¨
okay bestie, gather round, because we're talking about Tickit::Widget::Button from the Tickit widget fam π this is a whole widget that shows a clickable button. you click it, a callback goes off. that's the vibe. it's giving interactive terminal glamour π
(also, lowkey, this page lives in the User Contributed Perl Documentation section of the manual, in case you were wondering where you wandered into π«Ά)
πΈ SYNOPSIS πΈ
here's the whole thing in action, no cap:
use Tickit;
use Tickit::Widget::Button;
my $button = Tickit::Widget::Button->new(
label => "Click Me!",
on_click => sub {
my ( $self ) = @_;
# Do something!
},
);
Tickit->new( root => $button )->run;
look at her. iconic. the label says hi, the on_click does the thing, and Tickit->new( root => $button )->run sets her loose π₯
π¦ DESCRIPTION π¦
so basically this class hands you a widget: a clickable area with a label on it. when someone clicks that area, a callback gets invoked. that's the entire plot, and honestly? it ate. π
π STYLE π
the default style pen is used as the widget pen β that's just how she shows up to the party. here's what style stuff gets used:
the following style keys are used:
linetype => STRINGβ what kind of border to draw around the button, and it has to be one of these four besties:
none single double thick
marker_left => STRINGβ a two-character string placed just before the button label π«Άmarker_right => STRINGβ a two-character string placed just after the button label π«
the following style tags are used:
:activeβ set when the mouse is being held over the button, before it is released π
the following style actions are used:
clickβ the main action, and the one that activates theon_clickhandler. periodt.
π CONSTRUCTOR π
new
$button = Tickit::Widget::Button->new( %args );
constructs a brand new Tickit::Widget::Button object. main character entrance, honestly.
takes the following named arguments:
label => STRβ the text to display in the button area β¨on_click => CODEβ optional! the callback function to invoke when the button is clicked. skip it if you want a button that just... exists. valid.
π ACCESSORS π
label
$label = $button->label;
set_label
$button->set_label( $label );
return or set the text to display in the button area. that's it, that's the whole job π
on_click
$on_click = $button->on_click;
set_on_click
$button->set_on_click( $on_click );
return or set the CODE reference that gets called when the button area is clicked:
$on_click->( $button );
note the $button gets passed in, iykyk π
click
$button->click;
behaves as if the button has been clicked, running its on_click handler. it's here for convenience, so other parts of your code can activate that handler programmatically. fake it till you make it, but make it correct β¨
align
set_align
valign
set_valign
$align = $button->align;
$button->set_align( $align );
$valign = $button->valign;
$button->set_valign( $valign );
accessors for the horizontal and vertical alignment of the label text inside the button area. and if you want the full lore, go see Tickit::WidgetRole::Alignable π¦
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk> β thank you for the gift, we are obsessed π«Ά
cute lil sign-off: this page isTickit...Button(3pm)from the User Contributed Perl Documentation, and it's tagging along withperl v5.40.0, dated2024-09-16. stay clickable bestie πβ¨
π¦ where this page comes from
- ubuntu resolute: libtickit-widgets-perl 0.42-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtickit-widgets-perl 0.42-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms