簡體   English   中英

如何從.py文件更改.kv文件中的TextInput框的hint_text

[英]how can i change the hint_text of TextInput box which is in .kv file , from .py file

我想在.py文件中定義的調用函數上更改.kv中文本框的hint_text

我知道標簽文本可以像這樣改變self.root.ids.tm.text ='[color =#FF0000] Time over [/ color]'但是在textbox ex self.root.ids的情況下同樣不起作用。 some_id.hint_text:“一些特殊的文字”

從App類中更改

使用self.root.ids.text_input_id.hint_text = "Something special"

從根類內更改

使用self.ids.text_input_id.hint_text = "Something special"

main.py

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder


Builder.load_string("""
<HintTextDemo>:
    orientation: 'vertical'
    TextInput:
        id: text_input
        hint_text: 'Write here'
    Button:
        text: 'Change hint text'
        on_release: app.change_hint_text() 
""")


class HintTextDemo(BoxLayout):
    pass


class TestApp(App):

    def build(self):
        return HintTextDemo()

    def change_hint_text(self):
        self.root.ids.text_input.hint_text = 'Type something here'


if __name__ == "__main__":
    TestApp().run()

產量

TextInput的提示文本 - 更改前 TextInput的提示文本 - 更改后

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM