在Kivy屏幕之后如何清除textinput?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (122)

我尝试清除textinput中的文本,但我在访问texinput属性时遇到问题。我想在释放按钮Acceppt并离开InputScreen后清除文本(entry.text)。我发现get_screen()来设置属性,但我现在不知道如何使用它与基维语言

ScreenManagement:
    id: screen_manager
    transition: FadeTransition()
    MainScreen:
        id: main_screen
        name: "main"
        manager: screen_manager
        numberSet1: input_screen.number1
        numberSet2: input_screen.number2
        numberSet3: input_screen.number3
    InputScreen:
        id: input_screen
        name: "input"
        manager: screen_manager
        textIdToReturn: main_screen.textName

<InputScreen>:

    NawiButton:
        tempNumber: key_board.entryText
        pos: root.width - 100 - 0.25 * root.width, 10
        text: "Acceppt"
        on_release: root.saveValue(root.textIdToReturn, self.tempNumber)
        background_normal: ''
        background_color: .3, 1, .4, .85

    KeyBoardGridLayout:
        id: key_board
        name: "KeyBoard"

<KeyBoardGridLayout>:
    rows: 5
    padding: [100, 10, 100, 100]
    spacing: 3
    entryText: entry.text

    BoxLayout:
        TextInput:
            id: entry
            font_size: 45
            multiline: False
            on_text: root.update_padding(args[0])
            padding_x: self.width/2


    BoxLayout:
        spacing: 3
        KeyBoardButton:
            text: "1"
            on_press: entry.text = root.addText(entry.text, self.text)
        KeyBoardButton:
            text: "2"
            on_press: entry.text = root.addText(entry.text, self.text)
        KeyBoardButton:
            text: "3"
            on_press: entry.text = root.addText(entry.text, self.text)

MainScreen类,但我认为并不重要:

<MainScreen>:
        BoxLayout:
            orientation: "vertical"
            spacing: 50
            padding: [300, 50, 300, 50]

            Button:
                text: root.numberSet1
                id: textNum1
                name: textNum1
                font_size: 45
                on_release:
                    root.touch("textNum1")
提问于
用户回答回答于

片段

ScreenManagement:
    id: screen_manager
    transition: FadeTransition()
    MainScreen:
        id: main_screen
        name: "main"
        manager: screen_manager
        numberSet1: input_screen.number1
        numberSet2: input_screen.number2
        numberSet3: input_screen.number3
    InputScreen:
        id: input_screen
        name: "input"
        manager: screen_manager
        textIdToReturn: main_screen.textName

        on_leave:
            root.ids.input_screen.key_board.entryText = ''
...

<InputScreen>:
    key_board: key_board

注意

kv文件 - ObjectProperty和ids

key_board: key_board

指示名为key_boardObjectProperty指向(挂接)到KeyBoardGridLayout的id key_board

entry

这是TextInput小部件的ID和弱引用。

entry.text

它引用了TextInput的属性text

entryText: entry.text

指示名为entryTextObjectProperty正在指向(连接)entry.text

所属标签

可能回答问题的人

  • 嗨喽你好

    7 粉丝480 提问9 回答
  • 富有想象力的人

    3 粉丝0 提问7 回答
  • uncle_light

    5 粉丝518 提问6 回答
  • 人生的旅途

    10 粉丝484 提问6 回答

扫码关注云+社区

领取腾讯云代金券