简体   繁体   English

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

[英]im working on a kivy project... i am using toggle buttons that are create from a function... how do i know what is selected?

here is the main python file...这是主要的python文件...

class MainWindow(Screen): def Get_Trending(self): Twitz = Trending_on_Twitter() Tikz = Trending_on_TikTok() ingrams = Trending_on_Instagram() class MainWindow(Screen): def Get_Trending(self): Twitz = Trending_on_Twitter() Tikz = Trending_on_TikTok() ingrams = 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

here is my kivy file...这是我的 kivy 文件...

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"

everything is working fine when it comes to being able to see my buttons and being able to scroll thru them... i can click them... but i added two buttons... select all and next... i just dont understand how to get the states of these buttons and when i click select all to select all... and when i click next get it to add which buttons were selected to either a list or dictionary or anything really...当谈到能够看到我的按钮并能够滚动它们时,一切正常......我可以点击它们......但我添加了两个按钮......选择全部和下一步......我只是不明白如何获取这些按钮的状态以及当我单击全选以全选时...当我单击下一步时,将其添加到列表或字典或任何真正的任何东西中选择了哪些按钮...

thankx in advance提前致谢

num = 0 for item in Trending: mybutton = ToggleButton( text =Trending[num]) mybutton.bind(on_press = self.choices) self.ids.grid.add_widget(mybutton) num+=1 num = 0 对于趋势中的项目: mybutton = ToggleButton( text =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)

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

相关问题 如何阻止按钮在 kivy 中被按下两次 - How do I stop the buttons from getting pressed twice in kivy 如何使用Kivy创建多个按钮? - How can I create multiple buttons with Kivy? 我是 python 的新手,对编码了解不多,但想了解有关如何创建工作代码的更多信息 - I am new to python and do not know much about coding but wanna learn more on how to create working codes 我正在使用 Kivy 开发一个 Android 应用程序,我想知道如何在 Scrollview 中添加 MDCard? 目前我正在使用 kivyMD 和 Kivy - I am developing an Android app using Kivy and I wanted to know that how can I add MDCard in Scrollview? Currently I am using kivyMD and Kivy 我怎么知道我是在调用numpy.array()还是使用内置数组函数? - How do I know if I am calling numpy.array() or using built in array function? 如何在Android上运行kivy创建项目? - How do I create a project in kivy running on android? 如何创建一个按钮,并为其分配一个 function? Python, Kivy - How do I create a button, and assign a function to it? Python, Kivy function str() 不起作用,我不知道该怎么办 - The function str() is not working and I do not know what to do GCS如何知道我正在使用哪个项目? - How does GCS know which project am I using? 如何使用 github 从 kivy 创建一个 apk 文件 - How do I create an apk file from kivy with github
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM