Python 在kivy中使用自定义字体
我正在尝试创建一个简单的kivy软件,我需要为Python 在kivy中使用自定义字体,python,kivy,kivy-language,Python,Kivy,Kivy Language,我正在尝试创建一个简单的kivy软件,我需要为按钮.text使用自定义阿拉伯文字体 我已将自定义字体包括在文件中并尝试过,但它看起来就是这样的: 我不确定这是一个编码问题还是我需要在Kivy中使用不同的东西 这是我的密码: main.py 导入kivy 从kivy.app导入应用程序 从kivy.uix.widget导入widget 从kivy.core.window导入窗口 类MyGrid(小部件): 通过 班级后勤办公室(应用程序): def生成(自): 返回MyGrid() 如果uuuu
按钮.text
使用自定义阿拉伯文字体
我已将自定义字体包括在文件中并尝试过,但它看起来就是这样的:
我不确定这是一个编码问题还是我需要在Kivy中使用不同的东西
这是我的密码:
main.py
导入kivy
从kivy.app导入应用程序
从kivy.uix.widget导入widget
从kivy.core.window导入窗口
类MyGrid(小部件):
通过
班级后勤办公室(应用程序):
def生成(自):
返回MyGrid()
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
BackOffice().run()
后台.kv
#:import utils kivy.utils
<MyGrid>
canvas.before:
Color:
rgba: utils.get_color_from_hex('#a1d0f4')
Rectangle:
pos: self.pos
size: self.size
GridLayout:
cols: 1
size: root.width, root.height
Label:
text: 'logo here'
GridLayout:
cols: 2
Label:
text: ' vision logo goes here'
GridLayout:
cols:1
Button:
size: 700, 120
size_hint: None, None # <---
background_color: utils.get_color_from_hex('#0a74c4')
font_name: 'fonts/Shoroq-Font.ttf'
text: "إعدادت المستخدمين"
Image:
source: 'images/conference-256.png'
y: self.parent.y + 5
x: self.parent.x + 70
Button:
text:'button'
background_color: utils.get_color_from_hex('#0a74c4')
Button:
text:'button'
background_color: utils.get_color_from_hex('#0a74c4')
Button:
text:'button'
background_color: utils.get_color_from_hex('#0a74c4')
GridLayout:
cols: 3
Button:
text: 'button'
background_color: utils.get_color_from_hex('#ff0000')
Button:
text: 'button'
background_color: utils.get_color_from_hex('#0a74c4')
Label:
text: 'some text here'
#:导入utils kivy.utils
在以下情况之前:
颜色:
rgba:utils.get_color_from_hex('#a1d0f4'))
矩形:
pos:self.pos
大小:self.size
网格布局:
科尔斯:1
尺寸:根.宽度,根.高度
标签:
文字:“此处为徽标”
网格布局:
科尔斯:2
标签:
文字:“视觉标志在这里”
网格布局:
科尔斯:1
按钮:
尺寸:700120
大小提示:无,无#要使用的解决方案和
例子
main.py
主电压(千伏)
:导入utils kivy.utils
:
在以下情况之前:
颜色:
rgba:utils.get_color_from_hex('#a1d0f4'))
矩形:
pos:self.pos
大小:self.size
网格布局:
科尔斯:1
尺寸:根.宽度,根.高度
标签:
文字:“此处为徽标”
网格布局:
科尔斯:2
标签:
文字:“视觉标志在这里”
网格布局:
科尔斯:1
按钮:
尺寸:700120
大小提示:无,无#
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.properties import StringProperty
import arabic_reshaper
from bidi.algorithm import get_display
Builder.load_file("main.kv")
class MyGrid(Widget):
bidi_text = StringProperty('')
def __init__(self, **kwargs):
super(MyGrid, self).__init__(**kwargs)
reshaped_text = arabic_reshaper.reshape(u"إعدادت المستخدمين")
self.bidi_text = get_display(reshaped_text)
class BackOffice(App):
def build(self):
return MyGrid()
if __name__ == '__main__':
BackOffice().run()
#:import utils kivy.utils
<MyGrid>:
canvas.before:
Color:
rgba: utils.get_color_from_hex('#a1d0f4')
Rectangle:
pos: self.pos
size: self.size
GridLayout:
cols: 1
size: root.width, root.height
Label:
text: 'logo here'
GridLayout:
cols: 2
Label:
text: ' vision logo goes here'
GridLayout:
cols:1
Button:
size: 700, 120
size_hint: None, None # <---
background_color: utils.get_color_from_hex('#0a74c4')
font_name: 'fonts/Shoroq-Font.ttf'
text: root.bidi_text
font_size: sp(20)
Image:
source: 'images/conference-256.png'
y: self.parent.y + 5
x: self.parent.x + 70
Button:
text:'button'
background_color: utils.get_color_from_hex('#0a74c4')
Button:
text:'button'
background_color: utils.get_color_from_hex('#0a74c4')
Button:
text:'button'
background_color: utils.get_color_from_hex('#0a74c4')
GridLayout:
cols: 3
Button:
text: 'button'
background_color: utils.get_color_from_hex('#ff0000')
Button:
text: 'button'
background_color: utils.get_color_from_hex('#0a74c4')
Label:
text: 'some text here'