[英]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)
我正在嘗試更新名為“self.password_tracker”的標簽,因為名為“self.create_pass_input”的文本輸入中的文本發生了變化,但如果可能的話,可以用python語言給出答案,但不要更新
您可以修改您提到的代碼部分,如下所示:
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)
這將確保在TextInput
的文本更改時觸發on_text
方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.