【发布时间】:2018-10-03 18:18:45
【问题描述】:
假设我们有一个表单,该人在输入上写了一些东西,但需要全部清除,我将如何在 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)
*忽略 on_press 上的 uraConfig
我试过这种方法,效果很好:
Button:
text: 'Create Ura'
id: bt_create
on_press: root.uraConfig()
on_release: context_input.text = ''
我对 kivy 和 Python 很陌生,所以我不确定这是否是清除文本的最佳方法,但我做错了什么?或者,如果你们能以最好的方式提供一些启示。
【问题讨论】:
标签: python kivy python-3.6 kivy-language