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)

我正在尝试更新名为“self.password_tracker”的标签,因为名为“self.create_pass_input”的文本输入中的文本发生了变化,但如果可能的话,不会得到更新,可以用 python 语言给出答案

http://img3.mukewang.com/649a9e900001ba2507780594.jpg

狐的传说
浏览 75回答 1
1回答

拉风的咖菲猫

您可以修改您提到的代码部分,如下所示:&nbsp; &nbsp; def on_text(instance, value):&nbsp; &nbsp; &nbsp; &nbsp; if len(self.create_pass_input.text)&nbsp; < 5:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.password_tracker.text = 'Weak'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; else:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.password_tracker.text = 'Strong'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; self.create_pass_input = TextInput(text='', multiline=False)&nbsp; &nbsp; self.create_pass_input.bind(text=on_text)&nbsp; &nbsp; self.add_details.add_widget(self.create_pass_input)&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; self.add_details.add_widget(Label(text="Strong password's prevent hacking"))&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; self.password_tracker = Label()&nbsp; &nbsp; self.add_details.add_widget(self.password_tracker)这将确保on_text每当文本发生更改时都会触发方法TextInput。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python