我得到的是空框字符,而不是Ä字符。如何使它们显示在我的奇异应用程序上。我读了一些文章,建议将字体类型更改为支持这些字符的字体。我尝试了几次,但似乎并没有解决。
尝试了非常基本的Calibri字体,并且还随机选择了据说适合我的languange(AlegreyaSansSC)的字体
Python文件:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.properties import StringProperty, BooleanProperty
class Row(BoxLayout):
x1 = StringProperty('')
x2 = StringProperty('')
x3 = BooleanProperty(False)
def __init__(self, x1, x2, x3, **kwargs):
super(Row, self).__init__(**kwargs)
self.x1 = x1
self.x2 = x2
self.x3 = x3
class MyPopup(Popup):
pass
class MainScreen(Screen):
pass
class SecondScreen(Screen):
def fire_popup(self):
pops = MyPopup()
pops.open()
class ScreenManagement(ScreenManager):
def changescreen(self, value):
try:
if value !='main':
self.current = value
except:
print('No Screen named'+ value)
class testiApp(App):
def build(self):
self.title = 'Hello'
def add_more(self, x1, x2, x3):
addbutton = self.root.get_screen('Page2').ids.empty
addbutton.add_widget(Row(x1, x2, x3))
def remove(self):
container = self.root.get_screen('Page2').ids.empty
if len(container.children) > 0:
container.remove_widget(container.children[0])
testiApp().run()
KV。文件:
<MyPopup>:
id:pop
size_hint: .4, .4
auto_dismiss: False
title: 'XXX!!'
BoxLayout:
orientation:'vertical'
BoxLayout:
orientation:'horizontal'
Label:
text:'X1'
TextInput:
id: X1
Label:
text:'X2'
TextInput:
id:X2
CheckBox:
id:X3
BoxLayout:
orientation:'horizontal'
Button:
text:'Lisää'
on_release: app.add_more(X1.text, X2.text, X3.active)
Button:
text: 'Close'
on_press: pop.dismiss()
<Row>:
x1:''
x2:''
x3:False
Label:
text: root.x1
Label:
text: root.x2
CheckBox:
active: root.x3
ScreenManagement:
MainScreen:
name:'Main'
SecondScreen:
name:'Page2'
<MainScreen>:
name:'Main'
BoxLayout:
Button:
text:'Next Page'
on_release: app.root.current ='Page2'
<SecondScreen>:
name:'Page2'
BoxLayout:
orientation:'vertical'
BoxLayout:
orientation:'vertical'
Label:
text:'Popup Test'
ScrollView:
bar_width: 5
bar_color: 1,0,0,1 #red
bar_inactive_color: 0,0,1,1 #blue
effect_cls: 'ScrollEffect'
scroll_type:['bars','content']
GridLayout:
orientation: "vertical"
size_hint_y: None
height: self.minimum_height
row_default_height: 60
cols:1
id:empty
BoxLayout:
Button:
text:'Open Popup'
on_press: root.fire_popup()
Button:
text:'Add'
on_release: app.add_more()
Button:
text:'remove'
on_release: app.remove()
答案 0 :(得分:0)
似乎只有在我使用单独的py时,才会出现此问题。和kv文件。
我不认为问题是由单独的py和kv文件引起的。下面的示例正确显示了字符。
from kivy.base import runTouchApp
from kivy.lang import Builder
runTouchApp(Builder.load_file("main.kv"))
GridLayout:
cols: 2
Label:
text: 'Alegreya Sans SC font'
Label:
text: 'Roboto font (Default)'
Label:
text: 'Ä'
font_size: 56
font_name: '/home/iam/share/fonts/Alegreya_Sans_SC/AlegreyaSansSC-Medium.ttf'
Label:
text: 'Ä'
font_size: 56
我得到的是空框字符,而不是Ä字符。怎么做 它们显示在我的kivy应用程序上。
font_name:
,并提供提取文件夹的路径以及字体类型(例如AlegreyaSansSC-Medium.ttf
)。以下示例说明了使用属性font_name
显示字符Ä来使用不同的字体。 Kivy使用的默认字体是Roboto。
from kivy.base import runTouchApp
from kivy.lang import Builder
runTouchApp(Builder.load_string("""
GridLayout:
cols: 2
Label:
text: 'Alegreya Sans SC font'
Label:
text: 'Roboto font (Default)'
Label:
text: 'Ä'
font_size: 56
font_name: '/home/iam/share/fonts/Alegreya_Sans_SC/AlegreyaSansSC-Medium.ttf'
Label:
text: 'Ä'
font_size: 56
"""))