Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^7: Getting selection from Tkx text

by dabella12 (Acolyte)
on Apr 03, 2013 at 16:51 UTC ( [id://1026879]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Getting selection from Tkx text
in thread Getting selection from Tkx text

Here is my code

use Tkx; use Tkx::FindBar; use strict; use warnings; my $name; my $mw=Tkx::widget->new('.'); my $text=$mw->new_text(-width=>20,height=>10); my $findbar=$mw->new_tkx_FindBar(-textwidget=>$text); foreach(qw/David Mary William/) { $text->insert('end',"$_\n"); } $findbar->g_pack(); $text-g_pack(); $findbar->show(); $text->g_bind('<Return>',sub{$name=$text->get(qw/sel.first sel.last);p +rint "The name is $name\n"});

Replies are listed 'Best First'.
Re^8: Getting selection from Tkx text (typos)
by Anonymous Monk on Apr 03, 2013 at 23:51 UTC

    Well that doesn't compile Can't find string terminator "/" anywhere before EOF at blah.pl line 15.

    Even if I were to fix that typo, the typos just keep going

    Try again please

      Sorry the command should have read

      $text->g_bind('<Return>',sub{$name=$text->get(qw/sel.first sel.last/); +print "The name is $name\n"});

        Sorry the command should have read

        Um, thats not the only typo. No matter, here is some working code

        #!/usr/bin/perl -- ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" use strict; use warnings; use Data::Dump qw/ dd pp/; $Tkx::TRACE = 64; use Tkx; use Tkx::FindBar; my $name; my $mw = Tkx::widget->new( '.' ); my $text = $mw->new_text( -width => 20, -height => 10, ); foreach( qw/David Mary William/ ) { $text->insert( 'end', "$_\n" ); } my $findbar = $mw->new_tkx_FindBar( -textwidget => $text, ); $mw->g_bind( '<Control-f>' => [ \&Tkx::FindBar::show, $findbar ], +); $mw->g_bind( '<F3>' => [ \&Tkx::FindBar::next, $findbar ], +); $mw->g_bind( '<Shift-F3>' => [ \&Tkx::FindBar::previous, $findbar ], +); $mw->g_bind( '<Return>', \&fudge, ); $findbar->g_pack(); $text->g_pack(); $findbar->show(); Tkx::MainLoop(); sub fudge { dd( \@_ ); dd [ $text->m_tag_configure( 'highlight' ) ]; $name = $text->get( qw/highlight.first highlight.last/ ); print "The name is $name\n"; dd [ $text->tag( qw' ranges highlight' ) ]; $text->m_tag_add( 'sel', qw/highlight.first highlight.last/ ); $text->g_focus; ## g_focus is g_focus not m_focus $findbar->hide; } ## end sub fudge

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1026879]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-26 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found