[英]Kivy TextInput and Fonts
the code in question 有问题的代码
txt = TextInput(text='%s'%default, multiline=False, size_hint=(0.5,1))
txt.font_name = gAssets + "FreeSans.ttf"
Txt.font_size = 14
If I comment out the font_name attribute the text in the input lines up about right. 如果我注释掉font_name属性,则输入行中的文本大约正确。 (still sits a little bit high in the box but workable)
(仍位于盒子中高一点,但可行)
(using the normal TextInput with the default font (DroidSans.ttf))
(使用具有默认字体(DroidSans.ttf)的普通TextInput)
However once I uncomment the line that sets it to FreeSans.ttf (larger character set) It now sits way to high in the text field 但是,一旦取消注释将其设置为FreeSans.ttf(较大的字符集)的行,它现在在文本字段中的位置就很高
(using normal TextInput with FreeSans.ttf)
(将普通的TextInput与FreeSans.ttf一起使用)
I am using kivy 1.3 and have been unsuccessful at getting the padding attribute to work(however I would be happy to use it if someone could demonstrate how to use it with a TextInput.) 我正在使用kivy 1.3,但未成功使用padding属性(但是,如果有人可以演示如何将其与TextInput一起使用,我将很乐意使用它)。
You can alter padding inside your code using VariableListPropery . 您可以使用VariableListPropery更改代码内的填充。 Example:
例:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.textinput import TextInput
from kivy.properties import VariableListProperty
class MyTextInput(TextInput):
padding = VariableListProperty(['24dp', '48dp'])
class MyApp(App):
def build(self):
return MyTextInput(text='This is an example text', multiline=False)
if __name__ == '__main__':
MyApp().run()
This code requires 1.7 version, as noted in documentation of the widget . 如小部件的文档中所述 ,此代码需要1.7版本。 I recommend uprgrading as I don't even see any API archive anywhere to check how it was setted before.
我建议升级,因为我什至在任何地方都看不到任何API存档来检查它的设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.