2005年09月22日 星期四 12:40
不知道像下面的代码这样使用wxTreeCtrl是不是有问题? 运行的时候不能显示button
python2.3.4 + wxPython 2.6.1
import wx
>
> Mod = {'1':1,'2':2,'3':3}
>
> class Tree(wx.TreeCtrl):
> def __init__(self, parent ):
> wx.TreeCtrl.__init__(self, parent, -1, style = wx.TR_HAS_BUTTONS |
> wx.TR_EDIT_LABELS)
> # add ImagesButtons
> isz = (16,16)
> il = wx.ImageList(isz[0],isz[1])
> fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER,
> isz))
> fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN,
> wx.ART_OTHER, isz))
> fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER,
> isz))
>
> self.SetImageList(il)
>
> # add TreeList
> # root
> root = self.AddRoot("The Root")
> self.SetPyData(root, None)
> self.SetItemImage(root, fldridx, wx.TreeItemIcon_Normal)
> self.SetItemImage(root, fldropenidx, wx.TreeItemIcon_Expanded)
>
> # child and subchild
> items = Mod.keys()
> items.sort()
> for item in items:
> child = self.AppendItem(root, item)
> self.SetPyData(child, None)
> self.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal)
> self.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Expanded)
>
> class MainFrame(wx.Frame):
> def __init__(self, parent, id):
> wx.Frame.__init__(self, parent, -1)
> MyTree = Tree(self)
>
> class MyApp(wx.App):
> def OnInit(self):
> frame = MainFrame(None, -1)
> frame.Show(True)
> self.SetTopWindow(frame)
> return True
>
>
> def main():
> app = MyApp(0)
> app.MainLoop()
>
>
> if __name__ == "__main__":
> main()
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050922/1b9865ca/attachment.html
2005年09月22日 星期四 13:22
好象对于顶层结点是没有button。不过我也不确定,我的程序也是不显示的。 -- I like python! My Donews Blog: http://www.donews.net/limodou
2005年09月22日 星期四 13:36
在05-9-22,limodou <limodou at gmail.com> 写道: > > 好象对于顶层结点是没有button。不过我也不确定,我的程序也是不显示的。 > wxPython Demo 里面的例子是在各级别节点都可以显示button的, 不过它是先在class panel里面做了一个TreeCtrl的实例,然后再设定TreeCtrl的各个属性。 而且我这段代码也对子节点都加了button,也是看不到。 我不清楚我那样的写法和demo里面的例子有什么本质区别吗?我是初学者,如果问题比较愚蠢请勿见怪。:-) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050922/384f6ddc/attachment.html
2005年09月22日 星期四 13:38
在 05-9-22,zhang yunfeng<zhangyunfeng at gmail.com> 写道: > 在05-9-22,limodou <limodou at gmail.com> 写道: > > > > > > 好象对于顶层结点是没有button。不过我也不确定,我的程序也是不显示的。 > > > > wxPython Demo 里面的例子是在各级别节点都可以显示button的, 不过它是先在class > panel里面做了一个TreeCtrl的实例,然后再设定TreeCtrl的各个属性。 > 而且我这段代码也对子节点都加了button,也是看不到。 > > 我不清楚我那样的写法和demo里面的例子有什么本质区别吗?我是初学者,如果问题比较愚蠢请勿见怪。:-) 例子中的顶层结点是root结点,它显示了一个图标,并没有button呀。它的子结点如果有子结点的话就有button了。 -- I like python! My Donews Blog: http://www.donews.net/limodou
2005年09月22日 星期四 13:57
要有这个属性: wx.TR_LINES_AT_ROOT ----------------------- Original Message ----------------------- From: zhang yunfeng <zhangyunfeng at gmail.com> To: limodou <limodou at gmail.com>, python-chinese at lists.python.cn Date: Thu, 22 Sep 2005 13:36:24 +0800 Subject: Re: [python-chinese] wxTreeCtrl无法显示buttons ---------------------------------------------------------------- > 在05-9-22,limodou <limodou at gmail.com> 写道: > > > > 好象对于顶层结点是没有button。不过我也不确定,我的程序也是不显示的。 > > > wxPython Demo 里面的例子是在各级别节点都可以显示button的, 不过它是先在class > panel里面做了一个TreeCtrl的实例,然后再设定TreeCtrl的各个属性。 而且我这段代码也对子节点都加了button,也是看不到。 > 我不清楚我那样的写法和demo里面的例子有什么本质区别吗?我是初学者,如果问题比较愚蠢请勿见怪。:-) --------------------- Original Message Ends --------------------
2005年09月22日 星期四 14:00
/blush, 是我搞混淆了。的确加上子节点之后就能看到button了。 我原来想问的问题应该是"节点前面的图标没有显示" 。现在我把self.SetImageList(il) 改成 self.AssignImageList(il) 就可以了显示图标了。不过为什么SetImageList不起作用呢? 在05-9-22,limodou <limodou at gmail.com> 写道: > > > 例子中的顶层结点是root结点,它显示了一个图标,并没有button呀。它的子结点如果有子结点的话就有button了。 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050922/93f21a76/attachment.htm
2005年09月22日 星期四 14:05
在05-9-22,张骏 <zhangj at foreseen-info.com> 写道: > > 要有这个属性: > wx.TR_LINES_AT_ROOT > 这个style看起来也不错, thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050922/2fa20c74/attachment.html
2005年09月22日 星期四 14:12
是不是你的il超出作用域被销毁了 你把他变成self.il试试 ----------------------- Original Message ----------------------- From: zhang yunfeng <zhangyunfeng at gmail.com> To: limodou <limodou at gmail.com>, python-chinese at lists.python.cn Date: Thu, 22 Sep 2005 14:00:55 +0800 Subject: Re: [python-chinese] wxTreeCtrl无法显示buttons ---------------------------------------------------------------- > /blush, 是我搞混淆了。的确加上子节点之后就能看到button了。 > 我原来想问的问题应该是"节点前面的图标没有显示" 。现在我把self.SetImageList(il) 改成 > self.AssignImageList(il) > 就可以了显示图标了。不过为什么SetImageList不起作用呢? > > 在05-9-22,limodou <limodou at gmail.com> 写道: > > > > > > 例子中的顶层结点是root结点,它显示了一个图标,并没有button呀。它的子结点如果有子结点的话就有button了。 > > > > --------------------- Original Message Ends --------------------
2005年09月22日 星期四 14:32
改成 self.il <http://self.il> 可以了 多谢。 在05-9-22,张骏 <zhangj at foreseen-info.com> 写道: > > 是不是你的il超出作用域被销毁了 > 你把他变成self.il试试 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050922/91af0852/attachment.htm
Zeuux © 2025
京ICP备05028076号