I am an experienced programmer learning perl by writing a sudoku program and it has gone very well. I am upgrading the cell edit routine (one of a 9x9 matrix) to make it cleaner and am having some trouble. Each cell is square and has 2 lines of up to 5 chars each currently using Tk::text.

I am having trouble filtering out not-allowed chars such as [a..zA..Z] and punctuation chars. I would like a "-validation" command callback like tk::entry has, but I need 2 lines of text. I have read up on bind and bindkey, but they tend to get too kludgy itemizing all the chars to filter out. I need to allow only [1..9], up, down, left, and right and block all else.

I need advice on which approach to use:

1. use the text widget with object/instance binding to bind all the unwanted chars?.

2. text widget subclassing, with text->InsertKeypress() method overridden with some filtering?

3.somehow make the entry widget work in pairs to simulate 2 lines with the first "flowing" into the second? (I have not researched this yet)

4.Some other widget or approach that I don't know about?

If you have any suggestions or words of wisdom, I would be grateful. Thanks -Eugene


In reply to Filtering/validating Tk::text input by NatureFocus

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.