【问题标题】:TreeCtrl wxPython selectedImageTreeCtrl wxPython selectedImage
【发布时间】:2012-12-05 04:57:46
【问题描述】:

您好,我想将所选图像放入 treeItemsCtrl 中,但我找不到尝试的方法

    fileopen = wx.Image("../iconos/folder-cerrado.png", wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()
    fileClose = wx.Image("../iconos/folder-abierto.png", wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()


    self.tree = wx.TreeCtrl(panel1, 1, wx.DefaultPosition, (-1,-1), wx.TR_HIDE_ROOT)
    root = self.tree.AddRoot('Home')
    os = self.tree.AppendItem(root, 'Documentos', image=fileAbierto, selectedImagefileCerrado)

但它不起作用,当我尝试运行它时出现此错误

os = self.tree.AppendItem(root, 'Documentos',fileAbierto,fileCerrado)

文件“/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode/wx/_controls.py”,第 5469 行,在 AppendItem 返回控件.TreeCtrl_AppendItem(*args, **kwargs) TypeError:在方法“TreeCtrl_AppendItem”中,预期参数 4 类型为“int”

我想在附加函数中执行此操作,因为我正在将项目添加到函数中,谢谢

【问题讨论】:

    标签: wxpython treecontrol


    【解决方案1】:

    wxPython 演示有一个示例。看起来您需要创建一个 ImageList 并提取 ID。然后,当您设置树的项目时,您将需要使用 SetItemImage 方法添加选定的图标:

    self.tree.SetItemImage(item, fileidx, wx.TreeItemIcon_Normal)
    self.tree.SetItemImage(item, smileidx, wx.TreeItemIcon_Selected)
    

    所以在演示中,它在未选中时会显示一个文件夹图标。然后当它被选中时,它会显示一个笑脸。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      • 2011-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多