【发布时间】:2020-04-02 05:58:23
【问题描述】:
我正在尝试创建一个需要用户输入坐标的游戏。但是,我意识到即使单击“Enter”按钮并更改屏幕,字段也不会被清除。通常使用普通的文本输入字段,我可以插入一个self.shootdepthinput.text='' 的python 行,这将清除字段中的文本输入,因为它是一个字符串。但是,对于 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}
【问题讨论】:
标签: python kivy kivy-language