I guess Tk's handling of keyboard input is ASCII-centric -- it probably doesn't know about any sort of "locale" or other mechanism whereby a given keycode (the byte value emitted when you press a shifted or unshifted alphabetic key) can be interpreted as something other than the standard ASCII value.

You could work around this for the Entry widget by binding a subroutine of your own to the "KeyRelease" event: each time a key is released, bind will call your sub and provide the keycode; now, all you need to do in that subroutine is to remap the ASCII codes to their Cyrillic equivalents (in whatever character encoding you happen to use for Russian).

I'm assuming that you have been able to use other Tk widgets (labels, listboxes, etc) with a suitable Cyrllic font in order to display strings in Russian. I'm also assuming that you are familiar with an appropriate keyboard mapping for Cyrillic input (e.g. the key that would be "S" on an English keyboard maps to "C" on a Russian keyboard, or whatever).

If these assumptions are correct, then it should be the case that when your KeyRelease-bound subroutine replaces ASCII keycodes with the proper Russian character codes, the Entry widget will display the Cyrillic characters that you want to see.

The subroutine probably won't be as simple as I've made it sound... First, the KeyRelease event will occur when you release any key -- and you only want to remap the ones that represent Cyrillic letters, so if the key just released is not a letter with a Cyrillic counter part, you should just leave it alone. Second, as the user types a string into the Entry, your subroutine may need to extract the widget's current string value, edit it, and insert it back into the widget, in order to make the Cyrillic characters show up as intended. This is not really a difficult issue -- just a tedious detail that you'll need to work out. (I'm sorry that I'm not in a position right now to try something out by way of example.)


In reply to Re: Russian input with Tk by graff
in thread Russian input with Tk by mamont

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.