Reputation: 4685
I'm using a RTL language and I need my text to be RTL. Is there a way to do it? And How can I justify my text? Example:
from tkinter import *
from tkinter.constants import *
root = Tk()
text = Text(root,,font=('Tahoma',8))#I need RTL and Right justified text!
text.grid()
scrl = Scrollbar(root, command=text.yview)
text.config(yscrollcommand=scrl.set)
scrl.grid(row=0, column=1, sticky='ns')
root.mainloop()
Upvotes: 6
Views: 9602
Reputation: 2362
This is not an direct answer for the current question; but is somehow related. In case of someone needs to write RTL
in an Entry
(Alternative to Textbox
or Input
in Tkinter) for farsi (persian), arabic and/or other RTL
languages; you can configure your Entry
like this:
from tkinter import *
win = Tk()
ent = Entry(win, justify="right")
ent.pack()
win.mainloop()
Upvotes: 0
Reputation: 11
1 Answer will solve that letters inside the word wrote correctly from right to left, but still, the new line position is on the left, and sentences do not begin from right to left like this example.
کلمات در فارسی باید حتما از راست شروع شوند نه از میان صفحه ، و خط جدید هم باید از طرف راست شروع شود .
if you see the second line begins from the middle of the page, like this. consider next line begins in the middle.
Upvotes: 0
Reputation: 93
i modified your code and it's worked!..
from tkinter import *
from tkinter.constants import *
root = Tk()
text = Text(root,,font=('Tahoma',8))#I need RTL and Right justified text!
text.tag_configure('tag-right', justify='right')
text.insert('end', 'text ' * 10, 'tag-right')
text.grid()
scrl = Scrollbar(root, command=text.yview)
text.config(yscrollcommand=scrl.set)
scrl.grid(row=0, column=1, sticky='ns')
root.mainloop()
in fact i add 2 lines code that set justify=CENTER
for a Text
widget fails: there is no such option for the widget.
What you want is to create a tag with the parameter justify
. Then you can insert some text using that tag (or you can insert any text and later apply the tag to a certain region)... Good luck! :)
Upvotes: 3