当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


wxPython wx.TreeCtrl ClearFocusedItem()用法及代码示例


在本文中,我们将学习与wxPython的wx.TreeCtrl类关联的ClearFocusedItem()方法。 ClearFocusedItem()是一种简单的方法,用于清除Tree Control当前关注的项目。

用法: wx.TreeCtrl.ClearFocusedItem(self)

参数:ClearFocusedItem()方法不需要任何参数。

代码示例:

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

输出窗口:

没有任何项目集中在树控件中




相关用法


注:本文由纯净天空筛选整理自RahulSabharwal大神的英文原创作品 wxPython – ClearFocusedItem() method in wx.TreeCtrl。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。