is there a way to write Persian in python kivy

余生长醉 提交于 2021-01-29 17:08:23

问题


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()

回答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



来源:https://stackoverflow.com/questions/65391292/is-there-a-way-to-write-persian-in-python-kivy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!