Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

How do I bind the Mousewheel to Tk::BrowseEntry?

by perltux (Monk)
on Apr 01, 2017 at 03:25 UTC ( [id://1186654] : perlquestion . print w/replies, xml ) Need Help??

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

Does anyone know the correct bindings to use a Mousewheel with Tk::BrowseEntry?

Specifically I would like to use the mousewheel in the Entry part (without even opening the pop-down list) of Tk::BrowseEntry to select the previous/next choice from the possible choices when moving the mousewheel up/down.
  • Comment on How do I bind the Mousewheel to Tk::BrowseEntry?

Replies are listed 'Best First'.
Re: How do I bind the Mousewheel to Tk::BrowseEntry?
by beech (Parson) on Apr 01, 2017 at 08:58 UTC

    Hi,

    This seems to work, UTSL saves the day

    #!/usr/bin/perl -- use strict; use warnings; use Tk; use Tk::BrowseEntry; { my $mw = tkinit(); my $var = 'initial label'; my $b = $mw->BrowseEntry(-label => "Label", -variable => \$var); $b->insert("end", "opt1"); $b->insert("end", "opt2"); $b->insert("end", "opt3"); $b->pack; WheelsUp($b ); $mw->focusFollowsMouse; MainLoop; } sub WheelsUp { my( $b ) = @_; my $mw = $b->toplevel; for my $wi ( $b, map { $_, $_->children } $b->children ){ $mw->bind( $wi, '<MouseWheel>',[ \&wheel_browse, $b, Tk::Ev('D +')]); $mw->bind( $wi, '<4>',[ \&wheel_browse , $b, 120]); $mw->bind( $wi, '<5>',[ \&wheel_browse , $b, -120]); $mw->bind( $wi, '<Up>',[ \&wheel_browse , $b, 1]); $mw->bind( $wi, '<Down>',[ \&wheel_browse , $b, -1]); } } sub wheel_browse { my( $main, $bro, $num ) = @_; my $lb = $bro->Subwidget("slistbox")->Subwidget('listbox'); $num = $num < 0 ? -1 : 1; $lb->UpDown( $num ); my $var_ref = $bro->cget( '-textvariable' ); $$var_ref = $lb->getSelected; return; } __END__
      Yes, it does work indeed, thank you very much!!

      I had spent hours on this previously getting nowhere, you clearly are a Perl genius!