Python 用Kivy中的按钮释放清除inputText

Python 用Kivy中的按钮释放清除inputText,python,kivy,python-3.6,kivy-language,Python,Kivy,Python 3.6,Kivy Language,让我们想象一下,我们有一个表单,其中一个人在输入上写了一些东西,但需要清除所有内容,我将如何在Kivy中做到这一点 我试过了,但没用: main.py: class CreateUra(GridLayout): def clear_inputs(self, *args): for item in args: item = '' class UraApp(App): def build(self): r

让我们想象一下,我们有一个表单,其中一个人在输入上写了一些东西,但需要清除所有内容,我将如何在Kivy中做到这一点

我试过了,但没用:

main.py:

class CreateUra(GridLayout):

    def clear_inputs(self, *args):
            for item in args:
                item = ''


class UraApp(App):

    def build(self):
        return CreateUra()

if __name__ == "__main__":
    UraApp().run()
Ura.kv:

<CreateUra>:
    cols: 1
    padding: 10
    spacing: 10
    row_force_default: True
    row_default_height: '32dp'

      BoxLayout:
            Label: 
                text: 'Contexto:'
                TextInput: 
                hint_text: "Contexto da ura"
                focus: True
                multiline: False
                cursor_color: (0, 0, 0, 0.8)
                id: context_input

        BoxLayout:
            Label: 
                text: 'Nome da ura:'
                TextInput: 
                hint_text: "Nome do arquivo da ura"
                multiline: False
                cursor_color: (0, 0, 0, 0.8)
                id: ura_file_name

        Button:
            text: 'Create Ura'
            id: bt_create
            on_press: root.uraConfig()
            on_release: root.clear_inputs(context_input.text, ura_file_name.text)

我对kivy和Python非常陌生,所以我不确定这是否是清除文本的最佳方式,但我做错了什么?或者,如果你们可以用最好的方法来做一些说明。

在你们的例子中,问题是传递文本,但不是文本属性,而是文本的副本,因此即使将其设置为空,也不会反映在textinput中。您必须以列表形式传递textinput,迭代并使用空字符串设置属性:

*.kv

Button:
    text: 'Create Ura'
    id: bt_create
    on_press: root.uraConfig()
    on_release: root.clear_inputs([context_input, ura_file_name]) # <-- add brackets
Button:
    text: 'Create Ura'
    id: bt_create
    on_press: root.uraConfig()
    on_release: root.clear_inputs([context_input, ura_file_name]) # <-- add brackets
class CreateUra(GridLayout):
    def clear_inputs(self, text_inputs):
        for text_input in text_inputs:
            text_input.text = ""