Reputation: 4731
In a kivy app, I have some text-input widgets, I would like to label it as a ghost text. By ghost text, I mean it passes no value to the number to be called later on.
For example, say, I have two text input entries in a kivy app.
TextInput:
text: '1st number'
id: first_id
input_filter: 'float'
multiline: False
TextInput:
text: '2nd number'
id: second_id
input_filter: 'float'
multiline: False
When the app is run, the first text input has a default text "1st number" and the second text input has a default text "2nd number". I am linking them to a function that add the two floating numbers together via a method. The problem is if users didn't enter anything and press the "run" button, it will break the app. Is there a way to make the text non-passable to the function?
And also, I want it to be in the background, so that users don't have to tap the text input and then delete the '1st number' writing before entering a number, any way to do that?
Upvotes: 1
Views: 376
Reputation: 8041
I think I have created a small example the creates the behavior you wanted. I created a new widget with a TextInput and a Label and its only showing the label if the value is empty...
a = Builder.load_string("""
<FloatInput@FloatLayout>:
empty_text: "Input a number"
value: float(txt.text or '0.0')
TextInput:
id: txt
input_filter: 'float'
Label:
center: txt.center
size: self.parent.size or (300,300)
text: "" if self.parent.value else self.parent.empty_text
font_size: txt.font_size
color: 0,0,0,1
BoxLayout:
FloatInput:
id: fi
Label:
text: "%s" % fi.value
""")
class SimpleApp(App):
def build(self):
return a
SimpleApp().run()
You may use this class as your input widget...
Upvotes: 1