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


> # 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).


#!/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->insert(0, "jimmy", "elayne", "craig", "don");


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";


use Tk;$c=tkinit->Canvas->pack;$x=45;for(split/_/,'KPI1_+09IPK_K;-OA1_+K!;A__1;

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