Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

wxPython – ClearFocusedItem() method in wx.TreeCtrl

  • Last Updated : 09 Jul, 2020

In this article we are going to learn about  ClearFocusedItem() method associated with wx.TreeCtrl class of wxPython. ClearFocusedItem() is a simple method and used in order to clear the currently focused item of Tree Control.

Syntax: wx.TreeCtrl.ClearFocusedItem(self)

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Parameters: No arguments are required by ClearFocusedItem() method.

Code Example:

import wx
class Tree(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        # create Tree Control in frame
        self.tree = wx.TreeCtrl(self, wx.ID_ANY, wx.DefaultPosition,
        # Create root for Tree Control
        self.root = self.tree.AddRoot('Root')
        # Add item to root
        item = self.tree.AppendItem(self.root, 'Item')
        # Clear focused item
        # expand tree
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.tree, 0, wx.EXPAND)
# main root frame for tree control
class rootframe(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent = None, title ='TreeCtrl Demo')
        panel = Tree(self)
if __name__ == '__main__':
    app = wx.App(redirect = False)
    frame = rootframe()

Output Window:

None of the item is focused in the tree control

My Personal Notes arrow_drop_up
Recommended Articles
Page :