如何将.kv文件中TextInput框的提示文本从.py fi更改为

2024-06-06 18:51:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我想更改.py文件中定义的调用函数的.kv中textbox的提示\u文本

我知道标签文字可以这样改变 self.root.ids.商标文本='[color=#FF0000]时间结束[/color]' 但对于textbox ex,这一点不起作用 self.root.ids一些_id.U文本:“一些特别的文字”


Tags: 文件py文本selfids定义root标签
1条回答
网友
1楼 · 发布于 2024-06-06 18:51:15

从应用程序类内更改

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

从根类内更改

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

示例

你知道吗主.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's Hint Text - Before ChangeTextInput's Hint Text - After Change

相关问题 更多 >