在本文中,我們將學習與wxPython的wx.TreeCtrl類關聯的EnsureVisible()函數。 EnsureVisible()方法使項目/根目錄在屏幕上可見。滾動和/或展開項目以確保給定的項目可見。
即使凍結了窗口,此方法也可以使用並且仍然有效(請參閱wx.Window.Freeze)。
用法: wx.TreeCtrl.EnsureVisible()
參數:
Parameter | Type | Description |
item | wx.TreeItemId | 我們想要確保可見的項目。 |
代碼示例:
Python3
import wx
class TreePanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.tree = wx.TreeCtrl(self, wx.ID_ANY, wx.DefaultPosition, (100, 50),
wx.TR_HAS_BUTTONS)
# create tree root
self.root = self.tree.AddRoot('root')
self.tree.SetPyData(self.root, ('key', 'value'))
# add items to root
item = self.tree.AppendItem(self.root, "Item")
item2 = self.tree.AppendItem(self.root, "Item")
item3 = self.tree.AppendItem(self.root, "Item")
item4 = self.tree.AppendItem(self.root, "Item")
focusitem = self.tree.AppendItem(self.root, "Focus Item")
# expand root
self.tree.Expand(self.root)
self.tree.EnsureVisible(focusitem)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.tree, 0, wx.EXPAND)
self.SetSizer(sizer)
def onclick(self, e):
# Delete si2 from the tree
self.tree.Delete(self.si2)
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()
輸出:
相關用法
- wxPython wx.TreeCtrl EditLabel()用法及代碼示例
- wxPython wx.TreeCtrl AssignImageList()用法及代碼示例
- wxPython wx.TreeCtrl Delete()用法及代碼示例
- wxPython wx.ToolBar AddSeparator()用法及代碼示例
- wxPython wx.TreeCtrl AppendItem()用法及代碼示例
- wxPython wx.StaticLine GetDefaultSize()用法及代碼示例
- wxPython wx.RadioButton GetValue()用法及代碼示例
- wxPython wx.RadioButton SetValue()用法及代碼示例
- wxPython wx.RadioBox ShowItem()用法及代碼示例
- wxPython wx.TreeCtrl AddRoot()用法及代碼示例
- wxPython wx.StaticLine GetClassDefaultAttributes()用法及代碼示例
- wxPython wx.StaticBox Enable()用法及代碼示例
- wxPython wx.RadioBox SetItemToolTip()用法及代碼示例
- wxPython wx.RadioBox SetSelection()用法及代碼示例
- wxPython wx.RadioBox SetString()用法及代碼示例
- wxPython wx.TreeCtrl ClearFocusedItem()用法及代碼示例
- wxPython wx.RadioBox GetString()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – EnsureVisible() method in wx.TreeCtrl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。