$txtBox->tagRanges('sel'); returns begin/end coordinates of selection in <x,y> 2D format and if I extract data from widget via get() method it will be 1D string. Is there simple method to convert coordinates to 1D?

$txtBox->tagRanges('sel'); doesn't return 2D coordinates, it returns the line.column of the selected text start and end point(s). If you get() the text between those endpoints, you will have the selected text.

my @ranges = $txtBox->tagRanges('sel'); my $text = $txtBox->get(@ranges[0,1]);
When I select anything, I get error 'Tk::Error: wrong # args: should be ".frame1.text get index1 ?index2 ...?" at C:/Perl/lib/Tk.pm line 252'

Because you are not giving the get() method any indicies to work with. Try:

if(@r) { my $str = $txtBox->get(@r);

Note that @r may have more than two coordinates. You may need to test and allow for them.

...if I use 'delete', 'insert' (and other Tk::Entry commands)...

Be aware that Tk::Entry methods != Tk::Text methods for the most part. There are many similarities, but many differences too. Do you want to do this with a Tk::Text box or a Tk::Entry? It would probably be easier with the Tk::Entry, it doesn't already have a defined action bound to the Return key. Tk::Text does, so you'll have to try to figure out what action the user meant when they hit Return. Not impossible, but a larger can of worms than I would want to open.


In reply to Re: Tk::Entry selection problem by thundergnat
in thread Tk::Entry selection problem by grizzley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.