所以我有一个ScrollView,它显示基于全局列表的按钮。看起来像这样
要创建此文件,我使用了此方法
def create_scrollview(self, dt):
global connectionList
base = [i for i in connectionList]
removeButton = ["X" for i in connectionList]
self.layout = GridLayout(cols=2, spacing=10, size_hint_y=None)
self.layout.bind(minimum_height=self.layout.setter("height"))
for element in base:
self.layout.add_widget(Button(text=element, size=(50, 50),
background_color = (.3, .3, .3, 1),
size_hint=(1, None)))
self.layout.add_widget(Button(text = 'X', size = (10, 10),
size_hint = (.15, .1),
background_normal = '',
background_color = (1 , .5, .5, 1)))
self.scrollview = ScrollView(size_hint=(1, None), size=(Window.width, Window.height))
self.scrollview.add_widget(self.layout)
self.view.add_widget(self.scrollview)
因此,基本上,当我单击按钮时,它需要触发两个功能,一个将“四个”添加到列表中,另一个调用该方法。
def resetScrollView(self):
global connectionList
base = [i for i in connectionList]
removeButton = ["X" for i in connectionList]
for element in base:
self.layout.add_widget(Button(text=element, size=(50, 50),
background_color = (.3, .3, .3, 1),
size_hint=(1, None)))
self.layout.add_widget(Button(text = 'X', size = (10, 10),
size_hint = (.15, .1),
background_normal = '',
background_color = (1 , .5, .5, 1)))
print(connectionList)
因此,基本上,它会打印更新的connectionList(“第一”,“第二”,“第三”,“第四”) 但是用户界面未更新,并且保持不变。你们能告诉我如何使ScrollView镜像connectionList(列表上每个字符串的每个按钮)吗?