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 6230217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:42:26+00:00 2026-05-24T09:42:26+00:00

I am using wxPython and got a tree with some items. Now I need

  • 0

I am using wxPython and got a tree with some items.
Now I need a function which give me the tree item object by name.

For example:
item = self.GetItemByName(“MyStories”)

I can not find such function in the documentation.

Does anyone has any ideas?

  • 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-24T09:42:26+00:00Added an answer on May 24, 2026 at 9:42 am

    Here’s one way to find the first tree item with a specific label:

    def get_item_by_label(self, tree, search_text, root_item):
        item, cookie = tree.GetFirstChild(root_item)
    
        while item.IsOk():
            text = tree.GetItemText(item)
            if text.lower() == search_text.lower():
                return item
            if tree.ItemHasChildren(item):
                match = self.get_item_by_label(tree, search_text, item)
                if match.IsOk():
                    return match
            item, cookie = tree.GetNextChild(root_item, cookie)
    
        return wx.TreeItemId()
    
    result = get_item_by_label(tree, 'MyStories', tree.GetRootItem())
    if result.IsOk():
        print('We have a match!')
    

    But depending on what you’re displaying in the tree, there’s probably an easier way to handle it. The TreeCtrl already provides the tools to create references both ways between tree items and other objects as you fill the tree, and dict lookups are much faster and cleaner looking than what I just typed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

bear with me, I've been using wxPython for all of one day now. Short
When using py2exe to distribute Python applications with wxPython, some MSVC DLLs are usually
I'm using wxPython to create a GUI app. Right now I'm using a wx.CheckListBox
I am making a python tree visualizer using wxPython. It would be used like
I have a wxpython app designed using XRC which has a multiline textctrl inside
When using wxPython, is it possible to remove or disable the Preferences menu item
I recently did some work modifying a Python gui app that was using wxPython
I am using wxPython's HyperTreeList and I want to set the column width exactly
I've written an application using wxPython and various other small modules (xlrd, xlwrt, pyserial,
I'm writing a GUI application in Python using wxPython and I want to display

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.