I am newbie of kivy. I have a button to refresh list items from database, This is function bound to that button:
def refresh_account(self):
self.ids.grid.clear_widgets()
for d in self.listdata:
self.acc_grid.add_row(d, body_alignment, col_size)
scroll = ScrollView(size_hint=(0.9, 0.9), size=(400, 50000), scroll_y=0, pos=(40, -30))
scroll.clear_widgets()
print "scroll children : ", scroll.children
scroll.add_widget(self.acc_grid)
scroll.do_scroll_y = True
scroll.do_scroll_x = False
self.ids.grid.add_widget(self.scroll)
I recieve an error :
kivy.uix.widget.WidgetException: Cannot add "grid.DataGrid object at 0x7fd415756ce8", it already has a parent "kivy.uix.scrollview.ScrollView object at 0x7fd413771b48"
Any reason for this? I have removed all widget by scroll.clear_widgets()
and scroll children print out is "[]" ?
The error is not that scroll already has children, but that the grid you are trying to add to it already has a parent. You haven't given enough information to actually debug the problem, but it is probably that self.acc_grid
is not a child of self.ids.grid
and therefore still has a parent after calling clear_widgets
.
scroll = ScrollView(size_hint=(0.9, 0.9), size=(400, 50000), scroll_y=0, pos=(40, -30))
scroll.clear_widgets()
Also, the above snippet does nothing. You just instantiated the ScrollView
so it naturally has no children. If you thought otherwise, perhaps this can help lead to your error.
(Also also, using clear_widgets
is probably not really necessary, you could just update the existing widgets instead).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With