【问题标题】:KIVY: how to have same set of widgets on multiple screensKIVY:如何在多个屏幕上拥有相同的小部件集
【发布时间】:2017-10-31 03:12:57
【问题描述】:

我想在我的所有屏幕上添加相同类型的小部件。并且当单击这些添加的小部件中的任何一个时,它会从所有屏幕中删除。这是目前的做法

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)

这样做的问题是它只会删除被点击的图像,而不是其他屏幕上的图像。

【问题讨论】:

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


    【解决方案1】:

    试试这个:

    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
    

    【讨论】:

    • 但也别忘了减小l的值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多