有没有一种方法可以将双击变量或文件中的单元格时所做的编辑保存到文件中?我想能够编辑单元格和更新我的数据库(一个.txt文件)。以我从here中找到的代码作为可编辑列表控制的示例:
import wx
import wx.lib.mixins.listctrl as listmix
########################################################################
class EditableListCtrl(wx.ListCtrl, listmix.TextEditMixin):
''' TextEditMixin allows any column to be edited. '''
#----------------------------------------------------------------------
def __init__(self, parent, ID=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0):
"""Constructor"""
wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
listmix.TextEditMixin.__init__(self)
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
rows = [("Ford", "Taurus", "1996", "Blue"),
("Nissan", "370Z", "2010", "Green"),
("Porche", "911", "2009", "Red")
]
self.list_ctrl = EditableListCtrl(self, style=wx.LC_REPORT)
self.list_ctrl.InsertColumn(0, "Make")
self.list_ctrl.InsertColumn(1, "Model")
self.list_ctrl.InsertColumn(2, "Year")
self.list_ctrl.InsertColumn(3, "Color")
index = 0
for row in rows:
self.list_ctrl.InsertStringItem(index, row[0])
self.list_ctrl.SetStringItem(index, 1, row[1])
self.list_ctrl.SetStringItem(index, 2, row[2])
self.list_ctrl.SetStringItem(index, 3, row[3])
index += 1
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
self.SetSizer(sizer)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, wx.ID_ANY, "Editable List Control")
panel = MyPanel(self)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
编辑:萨克森州Rolf提供的解决方案的打印输出:
^{pr2}$如您所见,如果我像您一样尝试编辑它,则不会显示任何内容。在
我假设您想知道如何访问
listctrl
中的数据,而不是写入文件。可编辑的listcrl是一个鬼鬼祟祟的野兽,因为在您更新数据之前(使用
self.list_ctrl.SetStringItem()
),您在编辑之后看到的内容实际上并不在数据中。方法是绑定到
wx.EVT_LIST_END_LABEL_EDIT
,并对更改的listcrl项执行更新。本例希望向您展示如何访问已更改的项、访问整个listctrl、执行更新、访问整个(更新的)listctrl并最终创建可导出的数据。在
每次编辑后打印和输出。实际上,您可以在退出时或通过单击按钮来执行数据导出,而不是在每次编辑之后。在
编辑:
^{pr2}$福特金牛座1996年蓝色改为福特金牛座1996年绿色打印结果
在Linux操作系统上,wxpython“2.8.12.1(gtk2 unicode)”
相关问题 更多 >
编程相关推荐