Frage

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. (still sits a little bit high in the box but workable)

Normal alignment (uses DroidSans.ttf) (using the normal TextInput with the default font (DroidSans.ttf))

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

Kivy TextInput with FreeSans (using normal TextInput with 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.)

War es hilfreich?

Lösung

You can alter padding inside your code using 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. I recommend uprgrading as I don't even see any API archive anywhere to check how it was setted before.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top