在Kivy的屏幕外,文本输入有多清晰

时间:2018-06-02 19:59:29

标签: python kivy kivy-language

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

if indexPath.row == indexOfGray {
  //  gray color
}
else {
{
  // default color 
}

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

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)

1 个答案:

答案 0 :(得分:0)

在kv文件中,使用on_leave处的on_pre_leaveInputScreen:事件清除文本(entry.text)。

Screen Manage » API » Events

  

活动:

on_pre_leave: ()
     

屏幕即将发生时触发事件   已删除:已启动离开动画。

on_leave: ()
     

删除屏幕时触发的事件:   离开动画完成了。

片段

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.ids.entry.text = ''
...

<InputScreen>:
    key_board: key_board

注意

kv文件 - ObjectProperty和ids

key_board: key_board

表示名为 key_board ObjectProperty 指向(挂钩) KeyBoardGridLayout 的id, key_board

entry

它是 id 和TextInput小部件的弱参数。

entry.text

它引用了 TextInput 文本的值。

entryText: entry.text

entryText 是KeyBoardGridLayout的一个属性。如果窗口小部件没有具有给定名称的属性,则将自动创建ObjectProperty并将其添加到窗口小部件。 entryText 被赋值为 entry.text