【发布时间】:2018-03-27 14:35:50
【问题描述】:
我有一个 kivy 应用程序,它显示来自 windows 命令输出生成的 pandas 数据帧的数据。
在 GridLayout 我有一个按钮。我试图让按钮在运行其命令后从 GridLayout 中删除一行。 我已经想出了如何从 GridLayout 中删除按钮,但似乎无法弄清楚其余部分。
也可以通过重新运行 windows 命令并生成新数据框来刷新布局。
我查看了这个答案,但无法以有效的方式将其应用到我的代码中。
Kivy Removing elements from a Stack- / GridLayout
def removeRow(self, instance):
#This removes the button
self.remove_widget(instance)
#I've tried all 3 of these to refresh the GridLayout
super(MakeTable, self).__init__()
super(MakeTable, self).do_layout()
MakeTable.do_layout(self)
我的 init 用于构建 GridLayout
def __init__(self, **kwargs):
table = ["Stuff"]
df = pandas.DataFrame(table)
super(MakeTable, self).__init__(**kwargs)
self.cols = 2
for index, row in df.iterrows():
btnremove = Button(text="Remove")
btnremove.bind(on_press=self.removeRow)
self.add_widget(btnremove)
lblUser = Label(text=row['USERNAME'])
self.add_widget(lblUser)
【问题讨论】: