0
使用下面的代码,在我将信息输入到应用程序的文本框后,offset_back返回一个list和self.main,我的id .kv文件创建一个滚动视图 添加了布局,但当我尝试重新输入数据第二次发生这种情况:“raise Exception('ScrollView accept only one widget')”Kivy ScrollView exception raise Exception('ScrollView accept only one widget')
我需要重置自我。主要以某种方式,如果是的话,我怎么能做到这一点? 谢谢。
def set_back_offset(self):
layout = GridLayout(cols=1, spacing=10, size_hint_y=None)
layout.bind(minimum_height=layout.setter('height'))
# catch empty box input which is a str, as Decimal will throw error.
if self.initial_bet.text == str() or self.initial_odds.text == str():
pop_warning().open()
#make sure entered unicode text is numeric, if not throw pop-up warning
elif not unicode.isnumeric(self.initial_bet.text) or not unicode.isnumeric(self.initial_odds.text):
pop_warning().open()
else:# all is good, create widgets
for details in offset_back(Decimal(self.initial_bet.text), Decimal(self.initial_odds.text)):
btn = Button(text=str(details[0]), size_hint_y=None, height=40,background_color= (255,0,0,1))
layout.add_widget(btn)
self.main.add_widget(layout)
`
,谢谢,我明白了这个例外,我只是不知道如何去除孩子,这是我第一次使用任何gui,所以对我来说都是新的。如果我移除孩子,则没有任何东西返回到屏幕。我在self.main.add_widget(layout)后面做self.main.remove_widget(self.main.children [0])。我认为它会显示数据,然后删除孩子,我错了吗? –
您需要在添加新的*之前删除旧的*。我原以为它会比原来的描述早崩溃。无论哪种方式,请继续遵循这个总体思路来解决问题。 – inclement
我看到我的逻辑是倒退,我把self.main.remove_widget(self.main.children [0])放在方法的第一行,但我仍然得到相同的异常。我会继续按照你所建议的方式工作,并将解决它,再次感谢。 –