simon
simon

Reputation: 83

Label not updating in kivy

    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

kivy screenshot

Upvotes: 0

Views: 42

Answers (1)

amras
amras

Reputation: 1599

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.

Upvotes: 1

Related Questions