1
好吧,我这里有一个例子:wxPython的树CTRL图像
可运行实例
解压zip文件,然后运行否则它不会在所有
工作然而,当运行图像将不会被添加到那里树CTRL,它只会是错误。
代码(注意将不无图像运行,见上面的zip文件)
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
self.tree = wx.TreeCtrl(self, style = wx.TR_HIDE_ROOT)
self.root = self.tree.AddRoot("")
gr = self.tree.AppendItem(self.root, "Grooveshark")
pop_r = self.tree.AppendItem(gr, "Popular")
sr = self.tree.AppendItem(gr, "Search")
dr = self.tree.AppendItem(self.root, "Download")
pr = self.tree.AppendItem(self.root, "Pandora")
stat_r = self.tree.AppendItem(pr, "Stations")
image_list = wx.ImageList(16, 16)
grooveshark = image_list.Add(wx.Image("images/grooveshark (Custom).png", wx.BITMAP_TYPE_PNG).ConvertToBitmap())
popular = image_list.Add(wx.Image("images/popular (Custom).png", wx.BITMAP_TYPE_PNG).ConvertToBitmap())
search = image_list.Add(wx.Image("images/search (Custom).png", wx.BITMAP_TYPE_PNG).ConvertToBitmap())
download = image_list.Add(wx.Image("images/download (Custom).png", wx.BITMAP_TYPE_PNG).ConvertToBitmap())
pandora = image_list.Add(wx.Image("images/playlist_icon (Custom).png", wx.BITMAP_TYPE_PNG).ConvertToBitmap())
stations = image_list.Add(wx.Image("images/stations (Custom).png", wx.BITMAP_TYPE_PNG).ConvertToBitmap())
self.tree.SetPyData(gr, None)
self.tree.SetItemImage(gr, grooveshark, wx.TreeItemIcon_Normal)
self.tree.SetPyData(pop_r, None)
self.tree.SetItemImage(pop_r, popular, wx.TreeItemIcon_Normal)
self.tree.SetPyData(sr, None)
self.tree.SetItemImage(sr, search, wx.TreeItemIcon_Normal)
self.tree.SetPyData(dr, None)
self.tree.SetItemImage(dr, download, wx.TreeItemIcon_Normal)
self.tree.SetPyData(pr, None)
self.tree.SetItemImage(pr, pandora, wx.TreeItemIcon_Normal)
self.tree.SetPyData(stat_r, None)
self.tree.SetItemImage(stat_r, stations, wx.TreeItemIcon_Normal)
if __name__ == "__main__":
a = wx.App(False)
f = TestFrame()
f.Show()
a.MainLoop()
为什么?
我按照wxPython演示程序中的演示,没有运气。
您的代码似乎缺少。 – brc
它包含图像,所以它是在一个ZIP文件,否则将没有意义,因为没有图像的代码将不会运行 – Zimm3r
然而,你应该尝试在这里发布一个样本,因为很多问题可以发现,而没有实际运行代码。大多数人不会下载和解压缩代码,以帮助您找出问题所在。 – brc