5

I'm trying to use tkinter to create an application that using Arabic lang. the problem is the direction of cursor always from left to right that making user confused when selecting (highlighting )Arabic text inside an entry(the selected text get reversed letters position).

enter image description here

user2980054
  • 453
  • 1
  • 7
  • 21
  • It would be good to see the code that you're using so far, at least some part, not the whole thing, unless necessary, in order to see if this is maybe automatic or it goes against the ways of Arabic writing method. – jenko_cp May 05 '14 at 19:57
  • root =Tk();en=Entry(root);en.pack();root.mainloop()#simply this code (: – user2980054 May 05 '14 at 20:06
  • and it is automatic ..as you said.. but somebody looking for solution – user2980054 May 05 '14 at 20:11
  • you could try to convert into the correct display order using: `from bidi.algorithm import get_display; get_display(u'مرحبا العالم!')` -> `u'!\u0645\u0644\u0627\u0639\u0644\u0627 \u0627\u0628\u062d\u0631\u0645'` To install on Python 2: `pip install python-bidi`. – jfs May 06 '14 at 10:22
  • related: [right-to-left languages in Python](http://stackoverflow.com/q/3856403/4279) – jfs May 06 '14 at 10:25
  • @ JF.Sebastian <-- I think you misunderstand the problem..it is not about reshaping Arabic letters and reverse words..the problem is tkinter do not support writing from right to left..inspite of it is supporting Arabic as Unicode(utf-8)..I mean you can write in Arabic inside widgets ,you can set and get the characters normaly.but try to select a part of Arabic text inside entry ..if select the first letter of text; the highlighted part will show you the last letter of the text as shown in screenshot ^ – user2980054 May 06 '14 at 15:48
  • @user2980054: the suggestion is meant as a workaround. If some API returns text in the wrong order then you could use `get_display()` to get the correct order for display. As I understand [selection works weird for right-to-left languages in Tk](http://wiki.tcl.tk/3158) – jfs May 06 '14 at 18:41

1 Answers1

1

I think that you have to check the code of Tkinter.py and see if you can tweak it (but like creating an extension and not overwriting the code), maybe if you see that you can do something about these lines:

def get(self):
    """Return the text."""
    return self.tk.call(self._w, 'get')
def icursor(self, index):
    """Insert cursor at INDEX."""
    self.tk.call(self._w, 'icursor', index)
def index(self, index):
    """Return position of cursor."""
    return getint(self.tk.call(
        self._w, 'index', index))
def insert(self, index, string):
    """Insert STRING at INDEX."""
    self.tk.call(self._w, 'insert', index, string)
def scan_mark(self, x):
    """Remember the current X, Y coordinates."""
    self.tk.call(self._w, 'scan', 'mark', x)

All the previous lines are in the Entry class:

class Entry(Widget, XView):
    """Entry widget which allows to display simple text."""

I don't have references of support available for Arabic writing in Python, but that doesn't meant that it doesn't exists , maybe there is some dll or plugin waiting to be uncovered.

jenko_cp
  • 103
  • 1
  • 8