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

I have another Mousewheel question related to Tk::BrowseEntry.
On Linux when the pop-up listbox has a scrollbar, I can use the mousewheel to scroll the listbox without having to define any new bindings.
On Windows (Strawberry Perl) this does not work. The mousewheel does nothing.

So I have been trying to set up the binding myself but despite trying various subwidget targets (all those commented out in the example below) I haven't managed to get the mousewheel to scroll the listbox on Windows.

Does anybody know what the correct binding for this is?

#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my $mw=tkinit(); my $var='opt2'; my $b=$mw->BrowseEntry(-label => "Choose:", -variable => \$var, -style => 'MSWin32', -listheight => 5, -browsecmd => sub{ print STDOUT $var."\n" } ); $b->insert("end", "opt1"); $b->insert("end", "opt2"); $b->insert("end", "opt3"); $b->insert("end", "opt4"); $b->insert("end", "opt5"); $b->insert("end", "opt6"); $b->insert("end", "opt7"); $b->insert("end", "opt8"); $b->insert("end", "opt9"); $b->insert("end", "optA"); $b->insert("end", "optB"); $b->insert("end", "optC"); #my $lbx=$b->Subwidget("slistbox")->Subwidget("yscrollbar"); #my $lbx=$b->Subwidget("slistbox")->Subwidget("scrolled"); #my $lbx=$b->Subwidget("slistbox")->Subwidget("listbox"); #my $lbx=$b->Subwidget("choices"); my $lbx=$b->Subwidget("slistbox"); $lbx->bind('<MouseWheel>',[sub{$_[0]->yview('scroll',-($_[1]/120)*3,'u +nits')}, Ev("D")]); $b->pack; MainLoop;

Replies are listed 'Best First'.
Re: Tk::BrowseEntry listbox scrollbar with Mousewheel on Windows
by beech (Parson) on Apr 03, 2017 at 03:47 UTC
      Unfortunately, while your solution for my previous thread works great, I don't fully understand some of the code in your solution, so I'm a bit at a loss with regards to how to adapt it for the problem in this thread. :(


        What did I miss? You only want to yview and not select? Can you not copy WheelsUp and do yview instead of updown?


        If you remove your bind call and replace it with  $mw->focusFollowsMouse; then the Tk::Listbox natural wheel bindings work to scroll the listbox up down without changing the selection

        But if focusFollowsMouse is too much focus flipping, simply give the focus to the listbox when the button is pressed

        $b->Subwidget('arrow')->configure( -command => [ 'focus', $b->Subwidget('slistbox') ], );

        Also, $mw->WidgetDump can help you peek inside

Re: Tk::BrowseEntry listbox scrollbar with Mousewheel on Windows
by kcott (Archbishop) on Apr 03, 2017 at 10:54 UTC
      Yes, I did go through the source code of, that's how I found those various subwidgets to try (see the commented out lines in my example source code) but none of them seem to work when it comes to the mousewheel binding of the pop-up listbox on Windows.

      Tk::JBrowseEntry or Tk::JComboBox were considered in the past but they had other shortcomings that made them unsuitable and which made me choose BrowseEntry.