当我使用波斯语或阿拉伯语时,它从下到上显示多行文本。
from kivy.lang import Builder
import arabic_reshaper
from bidi.algorithm import get_display
from kivymd.app import MDApp
KV = '''
#:import arabic_reshaper arabic_reshaper
#:import get_display bidi.algorithm.get_display
Screen:
BoxLayout:
orientation: "vertical"
ScrollView:
do_scroll_x: False
do_scroll_y: True
index:1
MDCard:
id: md_card
orientation: "vertical"
padding: "8dp"
size_hint: None, None
size: 300, 300
#pos_hint: {"center_x": .5, "center_y": .5}
MDLabel:
font_name: 'font/Sahel.ttf'
text: get_display(arabic_reshaper.reshape('تست نام'))
halign: "right"
MDSeparator:
height: "1dp"
MDLabel:
font_name: 'font/Sahel.ttf'
halign: "right"
text: get_display(arabic_reshaper.reshape('این یک متن فارسی صرفا برای تست است در کیوی نمایش آن اشتباه از پایین به سمت بالا است.'))
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
Test().run()
它应该从上到下显示,提前感谢您的帮助。
这是您在此代码的输出中看到的图像。
我想要什么:
您需要使用
python-bidi
和arabic_reshaper
。
import arabic_reshaper
import bidi.algorithm
reshaped_text = arabic_reshaper.reshape("متن فارسی")
bidi_text = bidi.algorithm.get_display(reshaped_text)
然后使用
bidi_text
作为 Kivy 标签文本。
检查此链接以了解如何正确使用这些库。
链接>>>向她图书馆的程序员提出了一个问题,但仍然没有得到解答。
经过多次排查,我意识到问题出在这部分,但我无法让它像镜子一样解决显示波斯语和阿拉伯语文本的问题。
Lib\site-packages\kiv