I'm trying to center the text of a TextInput vertically in Kivy. But no solution yet.
How can I do a valign for text input in the kv file? Also centering horizontally would be great to know, how to do it.
For labels I have checked the text align example from Kivy and there the alginment is working because there you can use 'valign' and 'halign' to do the alignment, but that's not available for TextInputs.
Maybe a trick with texture_size could help, but I need to check how this works. I have seen such a trick for a label, but I don't know if it works for the TextInput.
Here's my kv code that I have right now:
#: set Buttonheight1 40
BoxLayout:
size_hint_y: None
height: Buttonheight1
Label:
id: _number_label
text: "Number:"
font_size: 10
size_hint_x: None
width: 50
canvas.after:
Color:
rgba: 1,0,0,.5
Rectangle:
pos: self.pos
size: self.size
TextInput:
multiline: False
size_hint_y: None
height: _number_label.height
#padding_top: 10
font_size: 10
text: str(self.font_size)
#text: '%s, %s' % (self.get_center_x(), self.get_center_y()) #position test
Explanation of the kv code:
- Buttonheight1 is a constant with kv set
- Canvas.after is just for debugging the size of the label
- The text of the text input shows font size as dummy text
Maybe it's simple to fix but I'm pretty new to Kivy and haven't found an example for this.
Here is how it looks like at the moment:
(Note: The OK button in the screenshot is not in the kv code above)