[英]Clearing MDTextField from kivymd after submission
我正在尝试创建一个需要用户输入坐标的游戏。 但是,我意识到即使单击“Enter”按钮并更改屏幕后,字段也不会清除。 通常使用普通的 textinput 字段,我可以插入一行self.shootdepthinput.text=''
,这将清除字段中的文本输入,因为它是一个字符串。 但是,对于 MDTextField,输入是元组的形式,它是不可变的。 有没有人知道我可以清除 MDtextfield 的功能? 谢谢!
这是我的 kivy 文件的摘录,我的 MDTextField 位于:
<ComputerScreen>:
shootxinput: shootxinput_id
shootyinput: shootyinput_id
shootdepthinput: shootdepthinput_id
id: "computerscreen_id"
name: "computer"
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: "battleshipgame.png"
GridLayout:
cols: 3
id: s_input
pos_hint: {"x":0.03,"y":0.72}
size_hint : 0.7, 0.1
MDTextField:
id: shootxinput_id
hint_text: "X-Coordinate"
required: True
helper_text_mode: "on_focus"
color_mode: "custom"
helper_text: "Enter a number from 1 to 10"
line_color_focus: 0, 0, 0, 1
MDTextField:
id: shootyinput_id
hint_text: "Y-Coordinate"
required: True
color_mode: "custom"
helper_text_mode: "on_focus"
helper_text: "Enter an alphabet from A to J"
line_color_focus: 0, 0, 0, 1
MDTextField:
id: shootdepthinput_id
hint_text: "Depth"
required: True
color_mode: "custom"
helper_text_mode: "on_focus"
helper_text: "0: Surface Level, 1: Sub-sea Level"
line_color_focus: 0, 0, 0, 1
FloatLayout:
id: buttonarea
Button:
id: shootsubmitbtn
size_hint:0.1,0.05
on_press: root.shoot()
text: "Enter"
pos_hint:{"x": 0.75, "y": 0.75}
创建一个语句来清除shoot
方法中的输入字段
def shoot(self, *args):
shootxinput_id.text, shootyinput_id.text = ""
# do some other things
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.