Tk::DoubleClick(3pm)
π NAME π
Tk::DoubleClick β correctly handle single-click vs double-click events, (yes bestie the trailing comma is canon, we do not question the ancients π)
So like. Your widget gets clicked. Was that one click? Two clicks?? The module knows. You don't have to. That's the whole vibe.
π VERSION π
Version 0.04
tiny version number, big main-character energy β¨
πΈ SYNOPSIS πΈ
use Tk::Doubleclick;
bind_clicks(
$widget,
[ \&single_callback, @args ], # Single callback with args
\&double_callback, # Double callback without args
-delay => 500,
-button => 'right',
);
β οΈ yes theuseline here really does sayTk::Doubleclickwith a lil lowercasec. That's what the page says. Copy it exactly, bestie, iykyk π«Ά
π¦ DESCRIPTION π¦
Tk::DoubleClick handles single-click vs double-click events correctly, calling only the callback that actually matches the event that happened. No double-firing. No chaos. No "why did my single-click handler run twice" 3am debugging sessions π
This module always exports bind_clicks().
like, you don't have to ask for it. it just shows up. iconic behavior honestly π
β¨ FUNCTIONS β¨
π«Ά bind_clicks() π«Ά
Required parameters:
$widgetβ the widget you're binding mousebuttons to. Usually aTk::Buttonobject, but honestly it could be almost any widget. the range?? unmatched. π[ \&single_click_callback, @single_click_args ]β the callback sub to invoke when the event is a single-click, plus the args to pass it. When there are no args to pass, you can just drop the brackets entirely. lowkey convenient.[ \&double_click_callback, @double_click_args ]β the callback sub to invoke when the event is a double-click, plus the args to pass it. Same deal: no args, no brackets needed. slay.
Options:
-delayβ max delay time detween clicks, in milliseconds. Default is300. If the second click of two proximate mouse clicks lands inside that delay window, the event counts as a double-click. If it doesn't, the two clicks are counted as two separate single-clicks (albeit nearly simultaneous ones). so like... timing is literally everything π-buttonβ which mouse button to bind. Your options are1,2,3, or the corresponding synonyms'left','middle', or'right'. The default is1('left').
π₯ EXAMPLE π₯
# Libraries
use strict;
use warnings;
use Tk;
use Tk::DoubleClick;
# User-defined
my $a_colors = [
[ '#8800FF', '#88FF88', '#88FFFF' ],
[ '#FF0000', '#FF0088', '#FF00FF' ],
[ '#FF8800', '#FF8888', '#FF88FF' ],
[ '#FFFF00', '#FFFF88', '#FFFFFF' ],
];
# Main program
my $nsingle = my $ndouble = 0;
my $mw = new MainWindow(-title => "Double-click example");
my $f1 = $mw->Frame->pack(-expand => 1, -fill => 'both');
my @args = qw( -width 12 -height 2 -relief groove -borderwidth 4 );
my @pack = qw( -side left -expand 1 -fill both );
# Display single/double click counts
my $lb1 = $f1->Label(-text => "Single Clicks", @args);
my $lb2 = $f1->Label(-textvar => \$nsingle, @args);
my $lb3 = $f1->Label(-text => "Double Clicks", @args);
my $lb4 = $f1->Label(-textvar => \$ndouble, @args);
$lb1->pack($lb2, $lb3, $lb4, @pack);
# Create button for each color, and bind single/double clicks to it
foreach my $a_color (@$a_colors) {
my $fr = $mw->Frame->pack(-expand => 1, -fill => 'both');
foreach my $bg (@$a_color) {
my $b = $fr->Button(-bg => $bg, -text => $bg, @args);
$b->pack(@pack);
bind_clicks($b, [\&single, $lb2, $bg], [\&double, $lb4, $bg]);
}
}
# Make 'Escape' quit the program
$mw->bind("<Escape>" => sub { exit });
MainLoop;
# Callbacks
sub single {
my ($lbl, $color) = @_;
$lbl->configure(-bg => $color);
++$nsingle;
}
sub double {
my ($lbl, $color) = @_;
$lbl->configure(-bg => $color);
++$ndouble;
}
four rows of colors, sixteen buttons, one Escape key to escape it all. the aesthetic?? immaculate π
π ACKNOWLEDGEMENTS π
Thanks to Mark Freeman for numerous great suggestions and documentation help. we love a documentation hero π«Ά
π AUTHOR π
John C. Norton, "<jchnorton at verizon.net>"
π BUGS π
Please report any bugs or feature requests to "bug-tk-doubleclick at rt.cpan.org", or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tk-DoubleClick
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. mutual notification arc fr fr β¨
π SUPPORT π
You can find documentation for this module with the perldoc command.
perldoc Tk::DoubleClick
You can also look for information at:
- RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-DoubleClick
- AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Tk-DoubleClick
- CPAN Ratings
http://cpanratings.perl.org/d/Tk-DoubleClick
- Search CPAN
http://search.cpan.org/dist/Tk-DoubleClick/
π ACKNOWLEDGEMENTS π
and yes bestie, the acknowledgements section really does show up twice in this doc. we are not editing it out. the Mark Freeman appreciation is load-bearing π«Άβ¨
Thanks to Mark Freeman for numerous great suggestions and documentation help.
π COPYRIGHT & LICENSE π
Copyright 2009 John C. Norton.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
okay that's the whole page!! go forth and bind your clicks correctly, bestie π β¨
this has been Tk::DoubleClick(3pm) β User Contributed Perl Documentation β from perl v5.34.0, dated 2022-06-28. no cap, that's the whole thing. byeeeee πΈπ¦π
π¦ where this page comes from
- debian bookworm: libtk-doubleclick-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtk-doubleclick-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtk-doubleclick-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtk-doubleclick-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtk-doubleclick-perl 0.04-2 Β· 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