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

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__

Replies are listed 'Best First'.
Re^2: How do I bind the Mousewheel to Tk::BrowseEntry?
by perltux (Monk) on Apr 01, 2017 at 12:46 UTC
    Yes, it does work indeed, thank you very much!!

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