本文整理汇总了Python中tkinter.ttk.Treeview.next方法的典型用法代码示例。如果您正苦于以下问题:Python Treeview.next方法的具体用法?Python Treeview.next怎么用?Python Treeview.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk.Treeview
的用法示例。
在下文中一共展示了Treeview.next方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ElementListWidget
# 需要导入模块: from tkinter.ttk import Treeview [as 别名]
# 或者: from tkinter.ttk.Treeview import next [as 别名]
#.........这里部分代码省略.........
Entry(self.selectedFrame, textvariable = self.label[1], bg = defaultValueBG) \
.grid(column = 4, row = 0, sticky = W + E)
# Виджет для элементов классов-потомков
self.detailFrame = Frame(self.selectedFrame)
self.detailFrame.grid(column = 3, row = 1, columnspan = 2, sticky = W + N + E + S)
self.selectedFrame.columnconfigure(3, weight = 1)
self.selectedFrame.columnconfigure(4, weight = 1)
self.selectedFrame.rowconfigure(1, weight = 1)
def onButtonUpClicked(self):
item = self.selectedItem()
if item is None: return
prev = self.tree.prev(item)
if prev != "":
parent, index = self.tree.parent(item), self.tree.index(item)
self.tree.move(item, parent, index - 1)
# Корректируем номера элементов
self.tree.set(item, "№", index - 1)
self.tree.set(prev, "№", index)
self.updateSelectedFrame(item)
def onButtonDownClicked(self):
item = self.selectedItem()
if item is None: return
next = self.tree.next(item)
if next != "":
parent, index = self.tree.parent(item), self.tree.index(item)
self.tree.move(item, parent, index + 1)
# Корректируем номера элементов
self.tree.set(item, "№", index + 1)
self.tree.set(next, "№", index)
self.updateSelectedFrame(item)
def onButtonAddClicked(self):
pass
def onButtonRemoveClicked(self):
item = self.selectedItem()
if item is None: return
next = self.tree.next(item)
self.tree.delete(item)
while next != "":
i = int(self.tree.set(next, "№"))
self.tree.set(next, "№", i - 1)
next = self.tree.next(next)
self.onSelectionChanged()
def onButtonApplyClicked(self, item = None):
if item is None: item = self.selectedItem()
示例2: NameView
# 需要导入模块: from tkinter.ttk import Treeview [as 别名]
# 或者: from tkinter.ttk.Treeview import next [as 别名]
class NameView(object):
"""Shows a treeview of unique names."""
def __init__(self, master, names):
self.widget = Frame(master)
self._tree = Treeview(self.widget, columns='name')
self._tree.grid(row=0,column=0, sticky=(N,S,W,E))
self._tree.view = self
self.widget.columnconfigure(0, weight=1)
self.widget.rowconfigure(0,weight=1)
self._tree.column('name', width=50)
self._tree['show'] = 'tree'
actions = {'edit': lambda e: self.edit(),
'search': lambda e: self.search(),
'focus_next': lambda e: self.focus_next(),
'focus_prev': lambda e: self.focus_prev(),
'select': lambda e: self._tree.selection_toggle(self._tree.focus()),
'clear_selection': lambda e: self._tree.selection_set([])
}
kb.make_bindings(kb.tagview, actions, self._tree.bind)
self._iids = dict()
self._names = dict()
logger.debug('Names: %s', names)
self.widget.focus_set = self._tree.focus_set
for name in sorted(names):
iid = self._tree.insert('', 'end', text=name)
self._names[iid] = name
self._iids[name] = iid
self._scroll = Scrollbar(self.widget, command=self._tree.yview)
self._tree['yscrollcommand'] = self._scroll.set
self._scroll.grid(row=0, column=1, sticky=(N, S))
self.widget.columnconfigure(1, weight=0)
def selection(self):
logger.debug('Selection: %s', self._tree.selection())
return [self._names[iid] for iid in self._tree.selection()]
def edit(self):
self._tree.event_generate('<<NameViewEdit>>')
def search(self):
if len(self._tree.selection()) == 0:
self._tree.selection_add(self._tree.focus())
self._tree.event_generate('<<NameViewSearch>>')
def append(self, names):
logger.debug('Append names: %s', names)
for name in names:
if name not in self._names.values():
iid = self._tree.insert('', 'end', text=name)
self._names[iid] = name
self._iids[name] = iid
def delete(self, name):
self._tree.delete(self._iids[name])
del self._names[self._iids[name]]
del self._iids[name]
def _focus(self, iid):
self._tree.focus(iid)
self._tree.see(iid)
def focus_next(self):
cur_iid = self._tree.focus()
next_iid = self._tree.next(cur_iid)
if next_iid == '':
iids = self._tree.get_children()
next_iid = iids[0]
self._focus(next_iid)
def focus_prev(self):
cur_iid = self._tree.focus()
prev_iid = self._tree.prev(cur_iid)
if prev_iid == '':
iids = self._tree.get_children()
prev_iid = iids[-1]
self._focus(prev_iid)
def jump_to(self, name):
try:
iid = self._iids[name]
self._focus(iid)
except KeyError:
pass
def get_names(self):
return tuple(self._names.values())
def set(self, names):
self._tree.delete(*self._iids.values())
self._iids.clear()
self._names.clear()
for name in sorted(names):
iid = self._tree.insert('', 'end', text=name)
self._names[iid] = name
self._iids[name] = iid