Updated 2011-07-05 02:22:25 by RLE

Richard Suchenwirth 2001-01-03 - Writing direction in some writing systems, notably Arab and Hebrew, goes from right to left. With little effort, a Tcl entry widget can be massaged to assume that behavior:
 proc rentry {w args} {
     bind rentry <Key> {
       if [string length %A] {%W icursor [expr [%W index insert]-1]}
     }
     eval entry $w -justify right $args
     bindtags $w [list $w Entry rentry . all]
 }
 # example usage: rentry .e -background grey -textvar foo ...

The characters you type in are appended at the left, because the cursor is moved one to the left after the character has been inserted. For decent Arabic or Hebrew entry, the keysyms coming in at %A must of course be mapped to the real characters they use.

Another approach would be an additional binding to Entry that moves the cursor if justification is "right":
 bind Entry <Key> {+
    if {[string length %A] && [%W cget -justify]=="right"} {
            %W icursor [expr [%W index insert]-1]}
 }

This way one would not need a new proc. Writing direction of an entry would depend on the selected justification.

I'm just not sure whether right-justification may be "justified" for numeric entry widgets, without wanting a reversal in writing direction...

VK 01-mar-2005 Both described here approaches are too simplistic, while normal right-to-left should also consider at the same time entering left-to-right numbers. For example MS-Word tries to behave this way somehow, but its guesses are low quality (at least on my version of MS-Word). Also referenced below A simple Arabic renderer explains this, and gives better code.

Lars H: The definitive reference for this sort of thing is Unicode Standard Annex #9 - The Bidirectional Algorithm (see [1], UAX 9). In an ideal world, the Tk widgets should have bidi-awareness built in.

See also A simple Arabic renderer - Heblish - The Lish family