有没有办法在python kivy中写波斯语 [英] is there a way to write Persian in python kivy

查看:80
本文介绍了有没有办法在python kivy中写波斯语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用python kivy编写波斯语,但无法正常工作.

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

推荐答案

您需要使用一些波斯字体. 我已经用阿拉伯文字完成了

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

您可以从此处下载

You can download the font from here

然后使用arabic_reshaper库使它成形.

Then use arabic_reshaper library to get it in shape.

pip install arabic-reshaper

您还需要python-bidi来翻转字母

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

pip install python-bidi

请参阅此 https://github.com/mpcabd/python-arabic-reshaper

代码

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

输出

这篇关于有没有办法在python kivy中写波斯语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆