Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

binding listbox with perl tkx

by Anonymous Monk
on Jan 17, 2017 at 17:15 UTC ( [id://1179773]=perlquestion: print w/replies, xml ) Need Help??

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

hello, i am using perl 5.22 with tkx on Windows 10. with tk, i succeed to bind buttonrelease-1 to a new_tk__listbox. but with tkx i do not succeed to bind the button to a new_tkx_Scrolled("listbox". that is to say, when i clic, Nothing happens. if somebody can look at this problem, that would be very fine for me, thanks by qadvance. here is my little test program.
use Tkx; use Tkx::Scrolled; use strict; my $lbox; my $mw= Tkx::widget->new("."); $mw->g_wm_minsize(200,200); $mw->g_wm_resizable(1,1); $mw->g_wm_focus(); display_main(); Tkx::MainLoop; sub clic { #$box_value=$sous_lbox2->get($sous_lbox2->curselection()); my $val=$lbox->curselection(); print "val=$val\n"; return if ($val eq ""); my $value=$lbox->get($lbox->curselection()); print "$value\n"; } sub display_main { # $lbox=$mw->new_tk__listbox(-height=>5,-selectmode => "single"); $lbox=$mw->new_tkx_Scrolled("listbox",-scrollbars=>"se",-height=>5,- +selectmode => "single"); $lbox->g_pack( -anchor=>'n', -padx=>3, -pady=>3, -expand=>1, -fill=>'both'); foreach my $key ("aa","bb","cc") { $lbox->insert('end', "$key- "); } $lbox->g_bind('<ButtonRelease-1>' , sub { clic() }); }

Replies are listed 'Best First'.
Re: binding listbox with perl tkx
by Marshall (Canon) on Jan 17, 2017 at 19:34 UTC
    Try binding to the main window instead of the listbox, i.e.:
    #make this change... #$lbox->g_bind('<ButtonRelease-1>' , sub { clic() }); $mw->g_bind('<ButtonRelease-1>' , sub { clic() });
Re: binding listbox with perl tkx
by beech (Parson) on Jan 18, 2017 at 00:02 UTC

    Hi,

    Try this from the documentation  $w->_kid('scrolled')->method(...) syntax.

    In your program that would be  $lbox->_kid('scrolled')->g_bind('<ButtonRelease-1>', \&clic, );

      thanks that "kid" trick works fine dont know exactly what it means, but it works fine , i added a second listbox and no confusion happen
Re: binding listbox with perl tkx
by Anonymous Monk on Jan 17, 2017 at 21:39 UTC
    hello, thanks it works better with bind to mW but suppose i have 2 widgets of that sort how would i distinguish clic on one or others, all driving to same sub clic ? or all activating sub clic and sub clic2 ... together ? i am quite astonished by that way of coding not at all the case with tk

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1179773]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2024-04-23 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found