0
我想在RootWidget
的remove
孩子小孩下面的例子中,但點擊RootButton刪除兩個孩子小部件(紅色和綠色的)。但是在shell中打印的self.children
列表中仍有第二個孩子,但不在RootWidget上查看。這裏做錯了什麼?Kivy remove_widget從屏幕中刪除所有的孩子小部件
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
RED = (1, 0, 0, 1)
GREEN = (0, 1, 0, 1)
class RootWidget(Button):
def __init__(self, *args, **kwargs):
super(RootWidget, self).__init__(*args, **kwargs)
self.add_widget(Button(background_color = RED), 0)
self.add_widget(Button(background_color = GREEN), 1)
self.bind(on_press = self.btn_call_back)
def btn_call_back(self, v):
try:
print "_" * 60
print self.children
print "+" * 60
self.remove_widget(self.children[0])
print self.children
print "_" * 60
except IndexError:
print "no children any more!"
class TutorApp(App):
def build(self):
return RootWidget()
if __name__ == "__main__":
TutorApp().run()