[英]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.