簡體   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