Crumbs, I though this would be trivial, but you're right. There is no
obvious way to do this via exposed properties. So here is a hack...The
TextInput has a hidden '_lines_labels' property. This is a list of
Labels, one for each row presumably? You could monitor the size of these to do what you want.
If anyone has a better way to do this, please speak now or forever hug your easter bunny....
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
class TestApp(App):
def build(self):
text_input = TextInput(pos_hint={'center_x':0.5, 'center_y': 0.5},
size_hint=(0.2, 0.1))
text_input.bind(text=self.text_changed)
float_layout = FloatLayout()
float_layout.add_widget(text_input)
return float_layout
def text_changed(self, text_input, text):
if len(text) > 0:
text_input.size_hint_x = None
text_input.width = text_input._lines_labels[0].width + 5
if __name__ == '__main__':
TestApp().run()