python - 如何使用按钮清除 TextInput
问题描述
我目前正在开发一个心理健康应用程序,但遇到了一个问题。每当我点击某个按钮时,我都需要清除 TextInput,但我不确定该怎么做。
作为参考,这是 TextInput:
TextInput:
id: text
font_size: (root.width**2 + root.height**2) / 15**4
multiline: False
pos_hint: {"x": 0.1 , "top":0.8}
size_hint: 0.8, 0.7
以及将触发它的按钮:
Button:
pos_hint: {"x": 0.0, "y": 0.95}
size_hint: 0.2, 0.05
text: 'Enter'
background_color: 0, 0, 0, 1
on_press: text.delete_selection()
本节的 Python 代码为:
class Screen_One(Screen):
text = ObjectProperty(None)
def delete_selection(self, from_undo=False):
if not self._selection:
return ("")
正如你所看到的,我尝试了一些东西,但它仍然没有效果,它不会清除文本输入。
有人可以帮帮我吗?提前致谢!
解决方案
text.text = ""
在你的python代码中会做到这一点。您可以创建一个类似的函数onclick
,如果您在一个整体类中,您可以调用self.text.text = ""
. 这将重置 TextInput 的文本。
推荐阅读
- python - 所有有效的可能组合
- gcc - 在 gcc 中安装 icuin
- python-3.x - sep=' ' 不工作。是什么原因?
- javascript - 如何让 Cypress.$ 在 while 循环中获取选择器的最新值
- javascript - 在 PDFKit 中使用子数组访问子数组的 Javascript - NODE JS
- java - If else 程序
- excel - 从 Excel 表中填充的下拉列表未正确选择
- javascript - nodejs - 如何在注册后强制用户完成个人资料?
- python - 有没有办法在熊猫数据框中识别行实际包含数据的列
- ios - 应用程序在调用自定义按钮的 setNeedsDisplay 时崩溃