I am working on a Tkinter application where I need to support the Farsi/Persian language. The title displays correctly, but the rest of the widgets don't show Persian text as expected. I want the text to be right-to-left (RTL), and the Persian letters should stick to each other.
Here's a simplified version of my code:
import tkinter as tk
from tkinter import messagebox
class InvoiceApp:
def __init__(self, master):
self.master = master
self.master.title("نرمافزار صورتحساب")
# لیست محصولات
self.products = []
# ایجاد ویجتها
self.product_label = tk.Label(master, text='نام محصول:', justify='right')
self.product_entry = tk.Entry(master)
self.price_label = tk.Label(master, text="قیمت:")
self.price_entry = tk.Entry(master)
self.add_button = tk.Button(master, text="افزودن به صورتحساب", command=self.add_to_invoice, justify='right')
self.create_invoice_button = tk.Button(master, text="ساخت صورتحساب", command=self.create_invoice)
self.send_email_button = tk.Button(master, text="ارسال ایمیل", command=self.send_email)
def add_to_invoice(self):
# افزودن محصول به لیست
pass
def create_invoice(self):
# ساخت صورتحساب
pass
def send_email(self):
# ارسال ایمیل
pass
if __name__ == "__main__":
root = tk.Tk()
app = InvoiceApp(root)
root.mainloop()
I have tried setting the font and anchor properties, but it doesn't seem to work as expected. Can someone guide me on how to configure Tkinter widgets to display Persian text correctly, right-to-left, and with letters sticking together?
Any help would be greatly appreciated! Thank you.
The problem can be fixed.
You are missing layout manager such as
place(),pack()orgrid().So, I used
grid().Add keyword
justify='right'for both Entry widgets.Btw, You haven't mention about
Textwidget. Actually, I leave it up to you.Snippet:
Screenshot: