Binding Button-1 to Listbox 
Author Message
 Binding Button-1 to Listbox

Hello all.

I have been trying to debug the following without success, and am now
trying to get some help from the gurus out there.

I am attempting to add a "bind" to Button-1 (I am assuming that is the
left mouse button; correct me if I'm wrong) to an event within a
Listbox.  The code is:

  my $sn_rest_list = $sn_rest_list_frame->Listbox(-width => 60,
                                       -selectmode => 'single',
                                       -exportselection => 0,
                                       -height => 15,
                                       -background => "white",
                                       -yscrollcommand => ['set',
$sn_rest_list_ysbar],
                                       -xscrollcommand => ['set',
$sn_rest_list_xsbar]);

  $sn_rest_list->bind(<ButtonPress-1>, sub {
                   print "Button Pressed\n";
                   my $new_index = $sn_rest_list->curselection;
                   print "My Index = $new_index\n";
                 });

Obviously, the callback will be more intensive, but is simplified here
for illustration.  Eventually, this "bind" will update a ROText widget
with information selected from within the Listbox.

Am I doing something wrong?  Can I not add a bind to a Listbox?

Any help would be greatly appreciated.

Regards,
Michael Cohen



Sat, 22 Dec 2001 03:00:00 GMT  
 Binding Button-1 to Listbox
Hello, all.

Just found my own answer.... Sometimes the most obvious solution is the
one that is right in front of your nose.  I left out the quotes around the
sequence, i.e., "<ButtonPress-1>".

Regards,
Michael Cohen

Quote:

> Hello all.

> <<text deleted to save space>>

>   $sn_rest_list->bind(<ButtonPress-1>, sub {
>                    print "Button Pressed\n";
>                    my $new_index = $sn_rest_list->curselection;
>                    print "My Index = $new_index\n";
>                  });



Sat, 22 Dec 2001 03:00:00 GMT  
 Binding Button-1 to Listbox

Quote:
> Hello all.

> I have been trying to debug the following without success, and am now
> trying to get some help from the gurus out there.

> I am attempting to add a "bind" to Button-1 (I am assuming that is the
> left mouse button; correct me if I'm wrong) to an event within a
> Listbox.  The code is:

>   my $sn_rest_list = $sn_rest_list_frame->Listbox(-width => 60,
>                                        -selectmode => 'single',
>                                        -exportselection => 0,
>                                        -height => 15,
>                                        -background => "white",
>                                        -yscrollcommand => ['set',
> $sn_rest_list_ysbar],
>                                        -xscrollcommand => ['set',
> $sn_rest_list_xsbar]);

>   $sn_rest_list->bind(<ButtonPress-1>, sub {

Oups, you have to quote the event
'<ButtonPress-1>' instead of just <ButtonPress-1>

- Show quoted text -

Quote:
>                    print "Button Pressed\n";
>                    my $new_index = $sn_rest_list->curselection;
>                    print "My Index = $new_index\n";
>                  });

> Obviously, the callback will be more intensive, but is simplified here
> for illustration.  Eventually, this "bind" will update a ROText widget
> with information selected from within the Listbox.

> Am I doing something wrong?  Can I not add a bind to a Listbox?

> Any help would be greatly appreciated.

> Regards,
> Michael Cohen




Sat, 22 Dec 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. binding right mouse button click to all buttons

2. Combine listbox, checkbox and button

3. Buttons and column alignment in listboxes

4. button-1 inside a listbox

5. highlight in listbox using Button-2

6. Inserting multiple buttons into a single line of a ListBox

7. How to bind a scroll bar to more than one listbox

8. bind Ev problem with listbox widget

9. listbox default bindings

10. Key Bindings for Listbox

11. Key Bindings for Listbox

12. Listbox-Bind question

 

 
Powered by phpBB® Forum Software