Page 1 of 1

Arabic text entry issue in tkinter

Posted: Sun Mar 01, 2020 5:55 pm
by e1661413
My python3 code:

Code: Select all

from tkinter import * #importing Tkinter Library
import tkinter.messagebox
 
win = Tk()

def led1ON(): #defining function led1ON
	print("button pressed") #to be printed on terminal
	tkinter.messagebox.showinfo("عنوان", "سلام " + txt.get() + "!")
	
led1Button = Button(win, text = "کلیک", command = led1ON, height = 2, width =8 ) #setting button naming led1Button
led1Button.place(x=37, y=50) #button position for led1Button #commanding to button to led1ON function
lbl = Label(win, text="نام:")
lbl.place(x=25, y=25)
txt = Entry(win,width=10)
txt.insert(INSERT,'نام')
txt.place(x=100, y=25)

win.mainloop()
In Windows 10 the result is OK:
Image

But in rPi the entry text is corrupted:
Image

Re: Arabic text entry issue in tkinter

Posted: Sun Mar 01, 2020 6:58 pm
by DirkS
I'm struggling to see the difference and peobably others too.
Can you describe what you mean by 'corrupted'?
Are the graphics distorted in some way (that's how it looks to me)?

Re: Arabic text entry issue in tkinter

Posted: Sun Mar 01, 2020 8:22 pm
by scruss
Linux doesn't do bidirectional text very well. I mean, it can, but most libraries aren't built with support built in. I don't know too much about Arabic (crashed out of lessons after month: fun language, amazing script, great teacher - but class was too far away after a long day) but I've seen some problems reported here with RTL languages before.

I tried using the libraries suggested here: python - Tkinter Label with arabic text - Stack Overflow and they still weren't right. They were a bit better, but I was probably still doing it wrong.

Notes for non-Arabic readers:

· Arabic is written from right to left (RTL), and when it's mixed with English or other LTR languages (becoming bidirectional, commonly ‘bidi’) does fun things with text display. Try selecting some text from the start of the code line beginning tkinter.messagebox… and drag the cursor along the line, watching the selection — it'll grow, then shrink, then grow again as you select the RTL and LTR bits.

· Arabic uses different letter forms depending on whether letters are at the end of a word (terminal; on the left), at the beginning (initial), in the middle (medial) or isolated outside words. The medial forms, to many latin script readers, tend to look quite similar. Writers of latin cursive tend to use variant forms quite freely, but they're not quite as formalized as in Arabic. The end goal is the same in both scripts: to create a pleasing flowing line. Printed English has almost totally lost variant forms except in really fancy typesetting where f+l becomes ‘fl’, f+f becomes ‘ff’ and swashes happen on initial capital letter Q and others. When it comes to swashes, though, Arabic sees English's swashes and says “Hold my Vimto” …

Re: Arabic text entry issue in tkinter

Posted: Mon Mar 02, 2020 8:02 pm
by e1661413
DirkS wrote:
Sun Mar 01, 2020 6:58 pm
I'm struggling to see the difference and peobably others too.
Can you describe what you mean by 'corrupted'?
Are the graphics distorted in some way (that's how it looks to me)?
Dear scruss did me a favor and describe it very well.
Problem is that the characters are separated from each other in a word and whole text is LTR instead of RTL.
Although as you can see in the messagebox, the title is shown correctly: "عنوان"
but in the messagebody, the text is shown "ن‌م م‌ا‌ن م‌ال‌س" instead of correct "سلام نام من"
Sorry if can't describe it in fluent english.

Re: Arabic text entry issue in tkinter

Posted: Mon Mar 02, 2020 8:21 pm
by e1661413
scruss wrote:
Sun Mar 01, 2020 8:22 pm
Linux doesn't do bidirectional text very well. I mean, it can, but most libraries aren't built with support built in. I don't know too much about Arabic (crashed out of lessons after month: fun language, amazing script, great teacher - but class was too far away after a long day) but I've seen some problems reported here with RTL languages before.

I tried using the libraries suggested here: python - Tkinter Label with arabic text - Stack Overflow and they still weren't right. They were a bit better, but I was probably still doing it wrong.

Notes for non-Arabic readers:

· Arabic is written from right to left (RTL), and when it's mixed with English or other LTR languages (becoming bidirectional, commonly ‘bidi’) does fun things with text display. Try selecting some text from the start of the code line beginning tkinter.messagebox… and drag the cursor along the line, watching the selection — it'll grow, then shrink, then grow again as you select the RTL and LTR bits.

· Arabic uses different letter forms depending on whether letters are at the end of a word (terminal; on the left), at the beginning (initial), in the middle (medial) or isolated outside words. The medial forms, to many latin script readers, tend to look quite similar. Writers of latin cursive tend to use variant forms quite freely, but they're not quite as formalized as in Arabic. The end goal is the same in both scripts: to create a pleasing flowing line. Printed English has almost totally lost variant forms except in really fancy typesetting where f+l becomes ‘fl’, f+f becomes ‘ff’ and swashes happen on initial capital letter Q and others. When it comes to swashes, though, Arabic sees English's swashes and says “Hold my Vimto” …
Dear scruss, I can't find thank you button so please let me say it here: THANK U VERY MUCH
I'll try that stackoverflow solution and inform you about the result.
As you said, arabic is RTL and has some similarities to english handwriting or cursive in attaching the letters in a word.
I'm down with you about the problem of linux because i use this code in windows and it works very well.
Also i've tested .net mono program and that also have this issue.
But if you check the native raspbian programs such as Mousepad or Leafpad or even LibreOffice, you'll see that everything is ok in this applications!
So i don't know whether the issue is from linux itself or from interpreters such as python and .net.
Kind Regards