python 从 wx.ListCtrl 打印内容

发布于 2024-11-02 16:05:15 字数 798 浏览 2 评论 0原文

时,我创建了一个列表,

self.statusListCtrl = wx.ListCtrl(self.panelUpper, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)

当我使用“当我的过程全部完成时”将数据添加到此列表

self.statusListCtrl.Append([datetime.datetime.now(),action,result])

我有一个很好的列表,显示已尝试的内容、该尝试的结果和日期时间戳。现在我想做的是将其输出到文本文件。我的问题是我无法正确从 listctrl 获取数据。

这就是我尝试迭代列表的方式。

fileName = 'd:\ssplogs\sspInstaller.log'
FILE = open(fileName,"w")

for itemIdx in range(0,self.statusListCtrl.GetItemCount()):
    line = str(self.statusListCtrl.GetItemText(itemIdx) + "\n")            
    print "line" , line        
    writeLine = line
    FILE.write(writeLine)

FILE.close()

我得到的输出只是我的日期时间戳,这是我列表的第一列。我如何得到这个,以便我看到类似的东西

datetime, action, result

I have a list created as

self.statusListCtrl = wx.ListCtrl(self.panelUpper, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)

I add data to this list using

self.statusListCtrl.Append([datetime.datetime.now(),action,result])

When my process is all done I have a nice list showing things that were tried, the result of that attempt and a datetime stamp. Now what I want to do is output that to a text file. my problem is that I cant get the data from my listctrl correctly.

This is how I am trying to iterate through the list.

fileName = 'd:\ssplogs\sspInstaller.log'
FILE = open(fileName,"w")

for itemIdx in range(0,self.statusListCtrl.GetItemCount()):
    line = str(self.statusListCtrl.GetItemText(itemIdx) + "\n")            
    print "line" , line        
    writeLine = line
    FILE.write(writeLine)

FILE.close()

The output I am getting though is only my datetime stamp, which is the first column of my list. How do I get this so I see something like

datetime, action, result

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久伴你 2024-11-09 16:05:15

使用它来获取行 x 列数据:

self.list.GetItem(row, col).GetText()

工作示例:

import wx

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.panel = wx.Panel(self)

        self.list = wx.ListCtrl(self.panel, style=wx.LC_REPORT)
        self.list.InsertColumn(0, "Date")
        self.list.InsertColumn(1, "Action")
        self.list.InsertColumn(2, "Result")

        for a in range(5):        
            self.list.Append(["Date %d" % a, "Action %d" % a, "Result %d" % a])

        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.list, proportion=1, flag=wx.EXPAND)

        self.panel.SetSizerAndFit(self.sizer)
        self.Show()

        # Save
        for row in range(self.list.GetItemCount()):
            print(", ".join([self.list.GetItem(row, col).GetText() for col in range(self.list.GetColumnCount())]))

app = wx.App(False)
win = MainWindow(None)
app.MainLoop()

Use this to get Row x Column data:

self.list.GetItem(row, col).GetText()

Working example:

import wx

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.panel = wx.Panel(self)

        self.list = wx.ListCtrl(self.panel, style=wx.LC_REPORT)
        self.list.InsertColumn(0, "Date")
        self.list.InsertColumn(1, "Action")
        self.list.InsertColumn(2, "Result")

        for a in range(5):        
            self.list.Append(["Date %d" % a, "Action %d" % a, "Result %d" % a])

        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.list, proportion=1, flag=wx.EXPAND)

        self.panel.SetSizerAndFit(self.sizer)
        self.Show()

        # Save
        for row in range(self.list.GetItemCount()):
            print(", ".join([self.list.GetItem(row, col).GetText() for col in range(self.list.GetColumnCount())]))

app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文