我发现下面显示的这个功能对于在树视图中向下移动非常有用,但我在这里问是否有向上移动功能。
def moveDown(self):
curSelection = self.tree.selection() # current row - from /68508694/
nextSelection = self.tree.next(curSelection) # next row
self.tree.selection_set(nextSelection) # set the next row to be the current row
self.tree.see(nextSelection) # make sure the current row is shown - from /10155153/
将其
nextSelection = self.tree.next
更改为prevSelection = self.tree.prev
,您应该检查是否有空值,请参阅评论:
def moveUp(self):
curSelection = self.tree.selection() # Get the current selection
if not curSelection: # If no row is selected, exit
return
prevSelection = self.tree.prev(curSelection) # Get the previous row
if prevSelection: # Check if there's a previous row
self.tree.selection_set(prevSelection)
self.tree.see(prevSelection)