http://qs321.pair.com?node_id=11120278

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

Dear monks

I'm struggeling with creating a scrolled listbox in Tk: the code below works, however I'm not able to scroll with the arrow-keys nor with the mouse-wheel. Do I have to bind the events myself and code the related actions? Or am I just missing something?

Thanks for your help! rata

sub selectProjectDialog_newtest { $mw = shift; # store the main window my @project_choices = split(" ","Project1 Project2 Project3 Proje +ct4 Project11 Project12 Project13 Project14 ") ; my $projectSelection_tl= $mw->Toplevel( ); $projectSelection_tl->title("Select the project:"); $projectSelection_tl->Label(-text => 'Select the project Id:', + )->grid(-row => 5, -column => 10, -sticky => "w"); my $scrolled1 = $projectSelection_tl->Scrolled ("Listbox", -scrollbars => "se", -width => 50, -height => 4, -selectmode => "extended") ->grid(-row => 10, -column => 10, -columns +pan => 10, -rowspan => 10); $scrolled1->insert ("end", @project_choices); }

Replies are listed 'Best First'.
Re: TK Listbox: scrolling with keys/mousewheel
by Anonymous Monk on Aug 04, 2020 at 09:00 UTC

      Thanks! That set me on the right track!

      A mixture between 1186926 and the sub wheel_browse from 1186662 works for me

      Rata

      sub selectProjectDialog_newtest { $mw = shift; # store the main window my @project_choices = split(" ","Project1 Project2 Project3 Proje +ct4 Project11 Project12 Project13 Project14 ") ; my $projectSelection_tl= $mw->Toplevel( ); $projectSelection_tl->title("Select the project:"); $projectSelection_tl->Label(-text => 'Select the project Id:', + )->grid(-row => 5, -column => 10, -sticky => "w"); my $scrolled1 = $projectSelection_tl->Scrolled ("Listbox", -scrollbars => "se", -width => 50, -height => 4, -selectmode => "extended") ->grid(-row => 10, -column => 10, -columns +pan => 10, -rowspan => 10); $scrolled1->insert ("end", @project_choices); $scrolled1->Subwidget('listbox')->bind('<Enter>', sub{$scrolled1-> +Subwidget('listbox')->focus()}); $scrolled1->Subwidget('listbox')->bind('<MouseWheel>',[ \&wheel_br +owse, $scrolled1, Tk::Ev('D')]); }