grizzley has asked for the wisdom of the Perl Monks concerning the following question:
I've read Tk manual, am aware of 'sel.first', 'sel.last'. It seems to me I won't have to translate from 2D to 1D format if I use 'delete', 'insert' (and other Tk::Entry commands) in some clever way.
In the comment at the end of the code is the idea of what I want to achieve. Any help/comment is welcome.
#!/usr/local/bin/perl use Tk; use Tk ':variables'; use strict; use warnings; # Main Window my $mw = new MainWindow; #GUI Building Area my $frm_name = $mw -> Frame(); #Text Area my $textarea = $mw -> Frame(); my $txt = $textarea -> Text(-width=>40, -height=>10); my $srl_y = $textarea -> Scrollbar(-orient=>'v',-command=>[yview => $t +xt]); my $srl_x = $textarea -> Scrollbar(-orient=>'h',-command=>[xview => $t +xt]); $txt -> configure(-yscrollcommand=>['set', $srl_y], -xscrollcommand=>[ +'set',$srl_x]); my $log = $textarea -> Text(-width=>40, -height=>2); #Geometry Management $frm_name -> grid(-row=>1,-column=>1,-columnspan=>2); $txt -> grid(-row=>1,-column=>1); $log -> grid(-row=>6,-column=>1); $srl_y -> grid(-row=>1,-column=>2,-sticky=>"ns"); $srl_x -> grid(-row=>2,-column=>1,-sticky=>"ew"); $textarea -> grid(-row=>5,-column=>1,-columnspan=>2); $txt->bind('<KeyPress>', [\&OnKeyPress, $txt]); my @dictionary = qw/rewelation reduction renowation reckonesance reval +uation reply/; $txt->focus; MainLoop; sub OnKeyPress { my $txtBox = $_[0]; # print 'Keysym=', $Tk::event->K, ', numeric=', $Tk::event->N, "\n +"; my @r = $txtBox->tagRanges('sel'); if(@r) { my $str = $txtBox->get(); my $sel = substr $str, $r[0], $r[1]-$r[0]; print 'selected: ', $sel; } } =the rest sub OnKeyPressed { if(key is <ENTER>) { accept_auto_complete_version() } elsif(matches_first_char_in_autocompletion_version()) { unselect this char; } else { unselect this char; find_other_autocompletion; } } =cut
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk::Entry selection problem
by zentara (Cardinal) on Apr 21, 2008 at 15:53 UTC | |
|
Re: Tk::Entry selection problem
by thundergnat (Deacon) on Apr 21, 2008 at 16:36 UTC | |
by grizzley (Chaplain) on Apr 22, 2008 at 06:35 UTC | |
|
Re: Tk::Entry selection problem
by grizzley (Chaplain) on Apr 28, 2008 at 09:25 UTC |