Python论坛  - 讨论区

标题:[python-chinese] 请教

2005年12月23日 星期五 15:04

Lea.Cen leacen at gmail.com
Fri Dec 23 15:04:44 HKT 2005

各位,我想问问,怎么实现动态的向listctrl中增加记录啊?
import wx
import sys

class win(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,id,title,size=(400,500))
        panel=wx.Panel(self,-1)
        self.task=Tasklist(panel,-1)
        self.Show(True)



class Tasklist(wx.ListCtrl):
    def __init__(self,parent,id):
        wx.ListCtrl.__init__(self,parent,id,size=(400,500),\
                             style=wx.LC_REPORT
                             |wx.BORDER_NONE
                             |wx.LC_SORT_ASCENDING
                             |wx.LC_VRULES
                             |wx.LC_HRULES
                             )
        self.SetFont(wx.Font(9,wx.SWISS,wx.NORMAL,wx.BOLD,False,'Verdana'))
        self.InsertColumn(0,"flag")
        self.InsertColumn(1,"Task")
        self.InsertColumn(2,"Remind")
        self.InsertColumn(3,"Delete")
        self.SetColumnWidth(1,150)
        self.setvalues()

    def setvalues(self):
        import cPickle as cp
        try:
            f=file("task.dat")
            c=cp.load(f)
        except (IOError):
            c=[{'task':'Write down your task',
               'time1':'2005-12-3','time2':'',
               'wtime':'09:30'}]
        f.close()
        print c
        n=len(c)
        for i in xrange(n):
            task=c[i].values()
            index=self.InsertStringItem(sys.maxint,task[0])
            wx.ListCtrl.SetStringItem(self,index,0,task[0])
            wx.ListCtrl.SetStringItem(self,index,1,task[1])
            wx.ListCtrl.SetStringItem(self,index,2,task[2])




class window(wx.App):
    def OnInit(self):
        frame=win(None,-1,"List test")
        frame.Raise()
        return True

app=window(0)
app.MainLoop()


--
Love Python!_______________________________________________
Python中文技术讨论邮件列表
发言: 发邮件到 python-chinese at lists.python.cn
订阅: 发送 subscribe 到 python-chinese-request at lists.python.cn
退订: 发送 unsubscribe 到  python-chinese-request at lists.python.cn
详细说明: http://python.cn/mailman/listinfo/python-chinese
My webSite: http://www.scweb.cn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051223/a97cc9df/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年12月27日 星期二 13:45

limodou limodou at gmail.com
Tue Dec 27 13:45:01 HKT 2005

在 05-12-23,Lea.Cen<leacen at gmail.com> 写道:
> 各位,我想问问,怎么实现动态的向listctrl中增加记录啊?
> import wx
> import sys
>
> class win(wx.Frame):
>     def __init__(self,parent,id,title):
>
> wx.Frame.__init__(self,parent,id,title,size=(400,500))
>         panel=wx.Panel(self,-1)
>         self.task=Tasklist(panel,-1)
>         self.Show (True)
>
>
>
> class Tasklist(wx.ListCtrl):
>     def __init__(self,parent,id):
>
> wx.ListCtrl.__init__(self,parent,id,size=(400,500),\
>                              style=wx.LC_REPORT
>                              |wx.BORDER_NONE
>                              |wx.LC_SORT_ASCENDING
>                              |wx.LC_VRULES
>                              |wx.LC_HRULES
>                              )
>         self.SetFont(wx.Font(9,wx.SWISS ,wx.NORMAL,wx.BOLD,False,'Verdana'))
>         self.InsertColumn(0,"flag")
>         self.InsertColumn(1,"Task")
>         self.InsertColumn(2,"Remind")
>         self.InsertColumn(3,"Delete")
>         self.SetColumnWidth(1,150)
>         self.setvalues()
>
>     def setvalues(self):
>         import cPickle as cp
>         try:
>             f=file("task.dat")
>             c=cp.load(f)
>         except (IOError):
>             c=[{'task':'Write down your task',
>                'time1':'2005-12-3','time2':'',
>                'wtime':'09:30'}]
>         f.close()
>         print c
>         n=len(c)
>         for i in xrange(n):
>             task=c[i].values()
>             index= self.InsertStringItem(sys.maxint,task[0])
>             wx.ListCtrl.SetStringItem(self,index,0,task[0])
>             wx.ListCtrl.SetStringItem(self,index,1,task[1])
>             wx.ListCtrl.SetStringItem(self,index,2,task[2])
>
>
>
>
> class window(wx.App):
>     def OnInit(self):
>         frame=win(None,-1,"List test")
>         frame.Raise()
>         return True
>
> app=window(0)
> app.MainLoop()
>
            index= self.InsertStringItem(sys.maxint,task[0])
            wx.ListCtrl.SetStringItem(self,index,0,task[0])
            wx.ListCtrl.SetStringItem(self,index,1,task[1])
            wx.ListCtrl.SetStringItem(self,index,2,task[2])

这就是呀。是不是把sys.maxin改为你指定的位置即可,上述做法的目的是在listctrl的最后添加,相当于append的功能。

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号