0

i try to write Persian in python kivy but it is not working.

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.lang import Builder
from kivy import Config
from kivy.uix.label import Label
from kivy.uix.widget import Widget


class MainApp(App):
    def build(self):
        return Label(text= "فارسی")

if __name__ == "__main__":
    MainApp().run()
Pykalier
  • 5
  • 3

2 Answers2

1

You need to use some Persian font. I have done it with Arabic text

You can download the font from here

Then use arabic_reshaper library to get it in shape.

pip install arabic-reshaper

You will also need python-bidi as well to flip the letters

pip install python-bidi

Refer to this https://github.com/mpcabd/python-arabic-reshaper

Code

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.lang import Builder
from kivy import Config
from kivy.uix.label import Label
from kivy.uix.widget import Widget
import arabic_reshaper
from bidi.algorithm import get_display

class MainApp(App):
    def build(self):
        reshaped_text = arabic_reshaper.reshape("فارسی")
        bidi_text = get_display(reshaped_text)
        
        return Label(text= bidi_text, font_name='Amiri-Regular.ttf', font_size=30)

if __name__ == "__main__":
    MainApp().run()

Output

enter image description here

Fadi Abu Raid
  • 831
  • 5
  • 13
0

Use Kivyir for Persian/Farsi.

pip install kivyir --user

Link GitHub

goldaaa
  • 19
  • 3
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 20 '23 at 20:54