當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


wxPython wx.TreeCtrl GetBoundingRect()用法及代碼示例

在本文中,我們將學習wx.TreeCtrl中的GetBoundingRect()方法。 GetBoundingRect()返回限製該項目的矩形。如果textOnly為True,則僅返回項目標簽周圍的矩形,否則,將考慮項目的圖像。如果未成功檢索矩形,例如當前不可見,則返回值可能為None。

GetBoundingRect()接受兩個參數item和textOnly。

Syntax: 

wx.TreeCtrl.GetBoundingRect(self, item, textOnly)

參數:



Parameter Type Description
item wx.TreeItemId 我們想要確保可見的項目。
純文本 boolean 如果textOnly為True,則僅返回項目標簽周圍的矩形,否則將考慮該項目的圖像。

Python

import wx  
  
  
class MyTree(wx.TreeCtrl):  
  
    def __init__(self, parent, id, pos, size, style):  
        wx.TreeCtrl.__init__(self, parent, id, pos, size, style)  
  
  
class TreePanel(wx.Panel):  
  
    def __init__(self, parent):  
        wx.Panel.__init__(self, parent)  
          
        # create tree control in window  
        self.tree = MyTree(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,  
                        wx.TR_HAS_BUTTONS)  
          
        # CREATE TREE ROOT  
        self.root = self.tree.AddRoot('root')  
        self.tree.SetPyData(self.root, ('key', 'value'))  
  
        # add item to root  
        item = self.tree.AppendItem(self.root, "Item")  
        item2 = self.tree.AppendItem(self.root, "Item")  
        item3 = self.tree.AppendItem(item, "SubItem") 
        item4 = self.tree.AppendItem(item, "SubItem") 
        item5 = self.tree.AppendItem(item2, "SubItem") 
        item6 = self.tree.AppendItem(item, "SubItem") 
  
        # print bound rectangle pyObject 
        print(self.tree.GetBoundingRect(item, False)) 
  
        # expand all nodes of the tree 
        self.tree.ExpandAllChildren(item)  
          
        sizer = wx.BoxSizer(wx.VERTICAL)  
        sizer.Add(self.tree, 0, wx.EXPAND)  
        self.SetSizer(sizer)  
  
  
class MainFrame(wx.Frame):  
  
    def __init__(self):  
        wx.Frame.__init__(self, parent = None, title ='TreeCtrl Demo')  
        panel = TreePanel(self)  
        self.Show()  
  
  
if __name__ == '__main__':  
    app = wx.App(redirect = False)  
    frame = MainFrame()  
    app.MainLoop()

輸出:

(0, 0 , 10, 10)





相關用法


注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – GetBoundingRect() method in wx.TreeCtrl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。