我要用kivymd提出一个申请,其中包含阿拉伯文和波斯文。
根据我的搜索,要做到这一点,您应该使用arabic_reshaper和bidi.algorithm,并使用支持波斯语和阿拉伯语的字体。因此,我能够这样编写代码,它很好地支持波斯语和阿拉伯语文本。
import kivy.app
import kivy.uix.label
import arabic_reshaper
import bidi.algorithm
class TestApp(kivy.app.App):
def build(self):
bidi_text = bidi.algorithm.get_display(arabic_reshaper.reshape("میلاد"))
return kivy.uix.label.Label(text=bidi_text, font_name="arial" , font_size="90sp")
testApp = TestApp()
testApp.run()现在,我的问题是,我想按如下方式编写我的程序,在这种方法中,我可以更改字体,但是我不能使用arabic_reshaper和bidi.algorithm方法,这会导致输出文本以这种方式显示。
from kivymd.app import MDApp
from kivymd.uix.screen import Screen
from kivymd.uix.label import MDLabel
from kivy.lang import Builder
import arabic_reshaper
import bidi.algorithm
screen_helper_up = """
Screen:
NavigationLayout:
ScreenManager:
Screen:
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: 'میلاد'
font_name:'arial.ttf'
left_action_items: [["menu", lambda x: nav_drawer.toggle_nav_drawer()]]
elevation:10
Widget:
Label:
text: "میلاد"
font_name:'arial.ttf'
markup: True
font_size: 100
color: 0,0,0,1
MDNavigationDrawer:
id: nav_drawer
"""
class DemoApp (MDApp):
def build(self):
screen = Screen()
screen = Builder.load_string(screen_helper_up)
return screen
DemoApp().run()正如您在下面的图像中所看到的,字体只在标签和MDToolbar标题中发生了更改,不幸的是,字体也没有改变。
发布于 2020-08-19 15:30:28
这就是我所做的:在Kv语言中,将文本引用到主应用程序中的一个变量(app.res3):
`text:app.res3`
`font_name:'PTBLDHAD'` 在主应用程序中,我应用reshaper模块如下:
`text3 = ("الصفحة الرئيسية")`
reshaped_texts3 = arabic_reshaper.reshape(text3)
res3 = get_display(reshaped_texts3)发布于 2020-08-20 17:01:35
@aiyad-alreshidi,谢谢您的回复,我按您所说的编辑了代码(当然,如果我做对了),并将其更改为以下代码:
from kivymd.app import MDApp
from kivymd.uix.screen import Screen
from kivy.lang import Builder
import arabic_reshaper
import bidi.algorithm
screen_helper_up = """
Screen:
NavigationLayout:
ScreenManager:
Screen:
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: app.res3
font_name:'iran.ttf'
left_action_items: [["menu", lambda x: nav_drawer.toggle_nav_drawer()]]
elevation:10
MDTextField:
text: app.res3
helper_text: app.res3
hint_text: app.res3
font_name: 'iran.ttf'
helper_text_mode: "persistent"
font_size: 30
line_color_focus: self.theme_cls.opposite_bg_normal
pos_hint: {'center_x': 0.5, 'center_y': 0.3}
size_hint: (0.5,0.4)
icon_right: "android"
Widget:
Label:
text: app.res3
font_name:'iran.ttf'
markup: True
font_size: 100
color: 0,0,0,1
MDNavigationDrawer:
id: nav_drawer
"""
class DemoApp (MDApp):
text3 = ("میلاد")
reshaped_texts3 = arabic_reshaper.reshape(text3)
res3 = bidi.algorithm.get_display(reshaped_texts3)
def build(self):
screen = Screen()
screen = Builder.load_string(screen_helper_up)
return screen
DemoApp().run()不幸的是,正如您在下面的图片中所看到的,字体只在标签和MDToolbar标题中或在MDTextField (helper_text和hint_text)中发生了变化,同样,它没有改变。

https://stackoverflow.com/questions/63462947
复制相似问题