忽略空白值每行的第一列(值1)
-
在kv文件中,删除子项
文本输入框
类中的小部件
一行
。
-
在Python脚本中,当实例化第一个
文本输入框
widget,提供
id='value1'
。
有关详细信息,请参阅下面的代码片段。
代码段
主要的py公司
class display(Screen):
def add_more(self):
self.ids.rows.add_row()
def insert(self):
rows = self.ids.rows
for row in reversed(rows.children):
for ch in reversed(row.children):
if isinstance(ch, TextInput):
if ch.text == "" and ch.id != 'value1':
print("\nch.id=", ch.id)
print("TextInput is required")
ch.focus = True
break;
class Row(BoxLayout):
button_text = StringProperty("")
def __init__(self, **kwargs):
super(Row, self).__init__(**kwargs)
self.add_widget(TextInput(id="value1", size_hint_x=0.4))
self.add_widget(TextInput(size_hint_x=0.4))
测验千伏
<Row>:
orientation: "horizontal"
spacing: 0, 5
Button:
text: root.button_text
size_hint_x: .2
检查每行的文本输入是否为空值
解决方案如下:
代码段
class display(Screen):
def add_more(self):
self.ids.rows.add_row()
def insert(self):
rows = self.ids.rows
for row in reversed(rows.children):
for ch in reversed(row.children):
if isinstance(ch, TextInput):
if ch.text == "":
print("TextInput is required")
ch.focus = True
break;
输出-忽略空白值每行的第一列(值1)
输出-检查每行的文本输入是否为空值