Sunday, April 5, 2026
HomeLanguageswxPython – ClearFocusedItem() method in wx.TreeCtrl

wxPython – ClearFocusedItem() method in wx.TreeCtrl

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)

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,
                                                 wx.DefaultSize,
                                                 wx.TR_HAS_BUTTONS)
  
        # 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
        self.tree.ClearFocusedItem()
  
        # expand tree
        self.tree.Expand(self.root)
  
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.tree, 0, wx.EXPAND)
        self.SetSizer(sizer)
  
# 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)
        self.Show()
  
  
if __name__ == '__main__':
    app = wx.App(redirect = False)
    frame = rootframe()
    app.MainLoop()


Output Window:

None of the item is focused in the tree control

Last Updated :
09 Jul, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32512 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6886 POSTS0 COMMENTS
Nicole Veronica
12007 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12100 POSTS0 COMMENTS
Shaida Kate Naidoo
7015 POSTS0 COMMENTS
Ted Musemwa
7259 POSTS0 COMMENTS
Thapelo Manthata
6972 POSTS0 COMMENTS
Umr Jansen
6960 POSTS0 COMMENTS