Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right to left text in tkinter

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()
like image 233
hamidfzm Avatar asked Oct 21 '22 19:10

hamidfzm


1 Answers

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! :)

like image 178
Mahdi Malekian Avatar answered Oct 23 '22 11:10

Mahdi Malekian