self.create_pass_input = TextInput(text='', multiline=False)
self.add_details.add_widget(self.create_pass_input)
self.add_details.add_widget(Label(text="Strong password's prevent hacking"))
self.password_tracker = Label()
if len(self.create_pass_input.text) < 5:
self.password_tracker.text = 'Weak'
else:
self.password_tracker.text = 'Strong'
self.add_details.add_widget(self.password_tracker)
I am trying to update the Label called 'self.password_tracker' as the text within the textinput called 'self.create_pass_input' changes but get no update if possible could answers be given in python language
You can modify the section of the code you mentioned like below:
def on_text(instance, value):
if len(self.create_pass_input.text) < 5:
self.password_tracker.text = 'Weak'
else:
self.password_tracker.text = 'Strong'
self.create_pass_input = TextInput(text='', multiline=False)
self.create_pass_input.bind(text=on_text)
self.add_details.add_widget(self.create_pass_input)
self.add_details.add_widget(Label(text="Strong password's prevent hacking"))
self.password_tracker = Label()
self.add_details.add_widget(self.password_tracker)
This will ensure triggering on_text
method whenever the text of the TextInput
changes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.