python - Kivy如何更新小部件
问题描述
所以我有一个 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 ('first','second','third','fourth') 但是 UI 没有更新并且保持不变。你们能告诉我如何使 ScrollView 镜像 connectionList(列表中每个字符串的每个按钮)
解决方案
推荐阅读
- javascript - Firebase 云消息订阅主题 Web 推送通知
- reporting - birt 报告获取 url 参数的值
- ssl - SAN 在 SSL 证书中被清除
- rust - 如何将闭包参数传递给具有生命周期参数的特征方法?
- javascript - 提交按钮后 10 秒无法显示模式,然后导航到另一个页面
- android - 如何在片段中实现导航抽屉
- java - 将 Object[] 从流转换为 byte[]
- c# - 模拟使用包含运算符而不是等于的连接?
- dji-sdk - 带 ROS 的 OSDK:在航路点拍照
- vba - 错误:“Excel 无法打开文件 'xxx.xlsm',因为文件格式无效。” 重新打开带有嵌入 VBA 代码的 xlsm 文件时