Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Tk : how to map ButtonRelease to left mouse button?

by Special_K (Monk)
on Apr 01, 2019 at 17:43 UTC ( [id://1231953]=perlquestion: print w/replies, xml ) Need Help??

Special_K has asked for the wisdom of the Perl Monks concerning the following question:

I am just getting started with Tk to make GUIs in Perl and am trying to make a button with a menu that appears when the user left-clicks on it. The following code does not produce any behavior when the button is left-clicked:

$pm->command(-label=>"rerun", -command=>[\&rerun, $dataset] ); $button->bind('<ButtonRelease-1>' => [ sub { push @menulist, $pm; $pm- +>post( $_[1], $_[2] ) }, Ev('X'), Ev('Y') ] );

On the other hand, the following does produce the desired menu when the button is right-clicked:

$pm->command(-label=>"rerun", -command=>[\&rerun, $dataset] ); $button->bind('<ButtonRelease-3>' => [ sub { push @menulist, $pm; $pm- +>post( $_[1], $_[2] ) }, Ev('X'), Ev('Y') ] );

If ButtonRelease-3 corresponds to the right mouse button, what corresponds to the left mouse button, if not ButtonRelease-1? I also tried ButtonRelease-2 but that didn't do anything either.

Replies are listed 'Best First'.
Re: Tk : how to map ButtonRelease to left mouse button?
by Discipulus (Canon) on Apr 01, 2019 at 19:55 UTC
    Hello Special_K,

    It must be 1. Play the following snippet:

    use strict; use warnings; use Tk; my $mw = tkinit; $mw->bind('<ButtonRelease>' => sub{ my($widget) = @_; my $e = $widget->XEvent; # get event object # ($keysym_text, $keysym_decimal) = ($e->K, $e->N) print "Button number ",$e->N," was released\n" } ); #ADD also this if unsure: #$mw->bind('<ButtonRelease-1>' => sub{ # print "Button number ONE was released\n" # } #); MainLoop;

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Tk : how to map ButtonRelease to left mouse button?
by tybalt89 (Monsignor) on Apr 01, 2019 at 20:36 UTC

    This works for me.

    #!/usr/bin/perl # https://perlmonks.org/?node_id=1231953 use strict; use warnings; use Tk; my $mw = MainWindow->new; $mw->geometry( '+300+300' ); my $button = $mw->Button(-text => 'Test', -command => sub { print "B1 released\n" }, )->pack; $button->bind('<ButtonRelease-1>' => sub { print "bind release\n" } ); MainLoop;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1231953]
Approved by LanX
Front-paged by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found