【发布时间】:2018-04-11 15:00:24
【问题描述】:
我正在尝试删除网格布局中的所有按钮,这些按钮是在按下按钮时动态创建的。我尝试使用 clear_widget() 执行此操作,但这不起作用。现在我为那些动态创建的按钮分配 id 并尝试删除它们,但它也不起作用
Python
def drinksSelect(self,value): # creating a button by referring the id of the layout in which to create button
drinkImagePath = {'pepsi': 'drinksPictures/pepsi.png','7up': 'drinksPictures/7up.png'}
if self.root.a_s.l < self.root.a_s.limit: # You know what I mean
st = 'number'
img = myImage(source= drinkImagePath[value], size=(200,20), id=st)
self.root.a_s.ids['place_remaining'].add_widget(img)
self.root.a_s.l += 1
def checkout(self): #when this fucntion is called, it should clear the gridLayout with id drinksLayout
#self.root.a_s.ids.drinksLayout.clear_widget(self.root.a_s.ids.place_remaining)
st = 'number'
self.root.a_s.ids.place_remaining.remove_widget(self.root.a_s.ids.st)
千伏
GridLayout:
id: drinksLayout
size_hint_y: 0.3
orientation: 'horizontal'
rows: 1
GridLayout:
id: place_remaining
rows: 1
size_hint_x: 80
Button:
id: label1
width: 200
size_hint: None,0.4
background_normal:'1.jpg'
text: 'Checkout'
on_release: app.checkout()
【问题讨论】:
标签: android python python-3.x kivy kivy-language