我想清除TextInput的text:,当我点击它。示例代码:
from kivy.app import App
from kivy.lang import Builder
kv_string = """
ScreenManager:
id: manager
Screen:
BoxLayout:
orientation: 'vertical'
Button:
text: 'Why does it clear multiple inputs? And why do they get cleared after touch_up?'
TextInput:
text: 'Write Your Name'
on_touch_down:
self.text = ''
TextInput:
text: 'Write Your Last Name'
on_focus:
self.text = ''
TextInput:
text: 'Write Your Phone Number'
on_touch_down:
self.text = ''
"""
class MyApp(App):
def build(self):
root_widget = Builder.load_string(kv_string)
return root_widget
if __name__ == "__main__":
MyApp().run()
无论是on_touch_down:或on_focus删除只是目前专注文字输入。相反,当我触摸屏幕上的任何地方时,两者都会被清除。一旦光标位于文本输入上,我希望它们单独清除。我也尝试过,on_cursor但这也不起作用。我错过了什么? 先感谢您!
相关分类