bind Ev problem with listbox widget 
Author Message
 bind Ev problem with listbox widget

Quote:

> # I would like to bind the middle mouse button to a callback
> # which knows which listbox element the curser was over when
> # the button was pushed and the callback was called.
> #
> # I have read the Tk::bind and Tk::event manpages and I am still
> unsuccessful.

Use XEvent to get the current event object and then use the x() and
y() methods to get the x and y coordinates. One caveat: because you're
using a scrolled listbox, you have to operate on the listbox subwidget
of the scrolled composite (the Subwidget call below).

Regards,
        Slaven

#!/usr/local/bin/perl -w
use Tk;
use strict;
my $mw = MainWindow->new();

my $lb = $mw->Scrolled('Listbox',
                -scrollbars => 'se',
                -selectmode => 'extended',
                -background => 'white',
                );
$lb->pack();

$lb->bind('<Button-2>',sub{print_index_value($lb)});

$lb->insert(0, "jimmy", "elayne", "craig", "don");

MainLoop();

sub print_index_value {
my $lb = shift;
my $e = $lb->Subwidget('listbox')->XEvent;
my $xloc = $e->x;
my $yloc = $e->y;

warn "$xloc $yloc";
print STDERR "The listbox element over which the middle mouse button\n";

Quote:
}

--
use Tk;$c=tkinit->Canvas->pack;$x=45;for(split/_/,'KPI1_+09IPK_K;-OA1_+K!;A__1;
Q!7G_1+QK_3CLPI90,_+K!;A_+1!KQ!.N_K+1Q!.F_1+KN.Q__1+KN._K+1Q!.F_1+KN.Q_+1Q__+1!
KQ!.N_1;Q!7G_K3,09Q_+1!K.Q_K+1Q!.F_1+KN.Q'){s/\n//g;for(split/!/){$c->create(
'line',map{$a=-43+ord;($x+($a>>3)*2,123+($a&7)*2)}split//)}$x+=12}MainLoop


Mon, 09 Jul 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Listbox binding problem

2. $widget->bind returns one binding only

3. Ev not working correctly during a callback on Text widget

4. Curses::Widgets::ListBox - Problem with ->input

5. Curses::Widgets::ListBox - Problem with input

6. Text Widget Bind Problem

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

8. Listbox-Bind question

9. binding <Key> to Listbox

10. Help for listbox->bind() needed

11. bind to listbox selection

12. simple listbox with binding question

 

 
Powered by phpBB® Forum Software