Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6813455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:34:20+00:00 2026-05-26T20:34:20+00:00

Ok I have an example here: Runable Example Example Extract the zip files and

  • 0

Ok I have an example here:

Runable Example

Example

Extract the zip files and then run otherwise it won’t work at all

However when run the images won’t be added to there tree ctrl and it will simply error.

Code (Note won’t run without images, see zip file above)

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()

Why?

I followed the demo in the wxPython demo app and no luck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:34:20+00:00Added an answer on May 26, 2026 at 8:34 pm

    There are 2 problems with you code.

    1. Not all of your images are 16px x 16px, but you are trying to add them to image list that should contain only 16 x 16 images. To solve this you should scale them to 16 x 16 before adding to a list.

    2. You should assign image list to tree object before applying images to tree items.

    Here is fixed code:

    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).Scale(16,16).ConvertToBitmap())
            popular     = image_list.Add(wx.Image("images/popular (Custom).png", wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
            search      = image_list.Add(wx.Image("images/search (Custom).png", wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
            download    = image_list.Add(wx.Image("images/download (Custom).png", wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
            pandora     = image_list.Add(wx.Image("images/playlist_icon (Custom).png", wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
            stations    = image_list.Add(wx.Image("images/stations (Custom).png", wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
    
            self.tree.AssignImageList(image_list)
    
            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()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed the onTouch example from google located here . However, I get
I currently have a csv file that I'm parsing with an example from here:
Here's the problem. I ,for example,have a string 2500.Its converted from byte array into
This is often situation, but here is latest example: Companies have various contact data
I have an interface - here's a nicely contrived version as an example: public
Here's an example of what I mean: I have an array: array('type'=>'text', 'class'=>'input', 'name'=>'username',
We have a Union Query. Here's a basic (similar) example: SELECT a.Name, b.Info FROM
Anybody have good examples of usability disasters? Here's an example. Hector is a manager
I have a generic list of objects in C#, for example sake, here's what
I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.