我正在处理一个基维项目...我正在使用从函数创建的切换按钮...我怎么知道选择了什么?

问题描述

这是主要的python文件...

MainWindow(Screen)类: def Get_Trending(self): twitz = Trending_on_Twitter() Tikz = Trending_on_TikTok() 英制= Trending_on_Instagram()

    Trending = Twitz + Tikz
    num = 0

    for item in Trending:
        button = ToggleButton(text=Trending[num])
        self.ids.grid.add_widget(button)
        num+=1

这是我的奇异文件...

BoxLayout:

        size_hint_y: .8
        orientation:"vertical"
        
        ScrollView:
            GridLayout:
                id:grid
                orientation:"vertical"
                size_hint_y: None
                height: self.minimum_height
                row_default_height:60
                cols:1
                Label:
                    id: top_area
                    text:"Trending On SocialMedia"
                    height: self.texture_size[1]
        BoxLayout:
            size_hint_y:.1
            orientation:"horizontal"
            Button:
                text:'Select All'
            Button:
                text:"next"

在能够看到我的按钮并能够通过它们滚动时,一切工作都很好...我可以单击它们...但是我添加了两个按钮...全选,然后选择下一步...我只是不了解如何获取这些按钮的状态,当我单击“全选”以全选...时,当我单击下一步时,将其添加到列表,字典或任何其他内容中。 >

提前谢谢

解决方法

num = 0 趋势中的项目: mybutton =切换按钮( 文字= Trending [num]) mybutton.bind(on_press = self.choices) self.ids.grid.add_widget(mybutton) num + = 1

def choices(self,coo):
    global Hash_Tags_Selected
    #print(coo.text)
    #print(type(coo.text))
    if coo.text in Hash_Tags_Selected:
        try:
            Hash_Tags_Selected.remove(coo.text)
        except:
            pass
    else:
        try:
            Hash_Tags_Selected.append(coo.text)
        except:
            pass
    print(Hash_Tags_Selected)