android - KIVY:如何清除其所有子项的网格布局

标签 android python python-3.x kivy kivy-language

我正在尝试删除网格布局中的所有按钮,这些按钮是在按下按钮时动态创建的。我尝试使用 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()

最佳答案

你只需要稍微修改一下你的checkout方法

    def checkout(self):  # when this fucntion is called, it should clear the gridLayout with id drinksLayout
        self.root.a_s.ids.place_remaining.clear_widgets()
        #but don't forget
        self.root.a_s.l = 0

关于android - KIVY:如何清除其所有子项的网格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47018513/

相关文章:

android - 当设备时间不正确时 GCM 是否工作?

python - 从 python 列表创建动态形状的张量以提供 tensorflow RNN

python - 如何使用守护进程 uwsgi 从 stderr 收集错误消息?

元组格式的python json数据不可解析

python - Ansible Community.aws.aws_ssm 模块。错误!一名 worker 被发现已死亡

python - 与 None 变量类型的比较

android - fragment 内的复选框 - 捕获选中/取消选中

android - 无法关闭 android eclipse 上的所有 Activity

Android:如何在顶部滚动 ScrollView

Python3 - 而 ids > 停止 : TypeError: unorderable types: str()> int()