繁体   English   中英

KIVY:如何在多个屏幕上使用同一组小部件

[英]KIVY: how to have same set of widgets on multiple screens

我想在所有屏幕上添加相同类型的小部件。 单击其中任何一个添加的小部件时,将从所有屏幕中删除该小部件。 这是当前的方法

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)
        img2 = myImage(source=drinkImagePath[value], size=(200, 20), id='soo')
        self.root.a_s.ids.place_remaining.add_widget(img)
        self.root.m_s.ids.place.add_widget(img2)
        self.root.a_s.l += 1

我正在使用此删除图像

class myImage (Image):
    def on_touch_down(self, touch):
        if self.collide_point(*touch.pos):
            self.parent.remove_widget(self)

这样做的问题在于,它仅删除单击的图像,而不删除其他屏幕上的图像。

尝试这个:

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)
        img2 = myImage(source=drinkImagePath[value], size=(200, 20), id='soo')
        img.twin = img2
        img2.twin = img
        button.a_s = self.root.a_s
        button2.a_s = self.root.a_s
        self.root.a_s.ids.place_remaining.add_widget(img)
        self.root.m_s.ids.place.add_widget(img2)
        self.root.a_s.l += 1


class myImage(Image):
    twin = ObjectProperty()
    a_s = ObjectProperty()

    def on_touch_down(self, touch):
        if self.collide_point(*touch.pos):
            self.parent.remove_widget(self)
            self.twin.parent.remove_widget(self.twin)
            self.a_s.l -= 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM