Clearing default text in TextInput on first click

2.5k Views Asked by At

I have a TextInput() widget that contains some default text.

enter image description here

When a user clicks inside the TextInput, the text that was initially inside the TextInput disappears (so that he can insert his own text without having to manually delete the default text).

  1. Is there an alternative way to replicate the above behavior? (e.g. some already existing attribute of TextInput)
  2. How can I make it reinsert automatically the text if the user didn't enter anything after clicking inside the TextInput and focused on some other widget. I tried on_unfocus: self.text = "(optionally add a description of the bug here)" but there is no unfocus attribute.

Code used:

from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

Builder.load_string("""
<Main>:
    Button:
        text: 'Send bug report button'
    TextInput:
        never_selected: False
        text: '(optionally add a description of the bug here)'
        on_focus: if self.never_selected == False: self.text = ''; self.never_selected = True
""")


class Main(BoxLayout):
    pass


if __name__ == '__main__':
    from kivy.base import runTouchApp
    runTouchApp(Main())
1

There are 1 best solutions below

0
On BEST ANSWER

It's in the docs: hint_text property

It is a StringProperty, empty by default.