亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Kivy 中使用按鈕釋放清除 inputText

在 Kivy 中使用按鈕釋放清除 inputText

慕勒3428872 2021-06-27 12:00:15
讓我們想象一下我們有一個表單,這個人在輸入上寫了一些東西但需要清除它們,我將如何在 Kivy 中做到這一點?我試過這個,但沒有用:主要.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()烏拉.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 很陌生,所以我不確定這是否是清除文本的最佳方式,但我做錯了什么?或者,如果你們能以最好的方式來做這件事。
查看完整描述

1 回答

?
喵喵時光機

TA貢獻1846條經驗 獲得超7個贊

您的情況的問題是傳遞文本,但不是文本屬性,而是文本的副本,因此即使將其設置為空也不會反映在文本輸入中。您必須將 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

*.py


class CreateUra(GridLayout):

    def clear_inputs(self, text_inputs):

        for text_input in text_inputs:

            text_input.text = ""


查看完整回答
反對 回復 2021-07-06
  • 1 回答
  • 0 關注
  • 327 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號