2015-12-21 84 views
0

用Tkinter运行python 2.7.8。我有一个移动列表框项目的功能。此功能起作用。但是,我还想要移动列表框选择(即指示器移动的东西)。移动tkinter listbox curser项目被移位?

我的换班功能是基于this thread。 这里是前名单: before_shift_function 和调用函数后: after_shift_function

我“从”选择到我的班哪有? Thx

def shift_sel_up(seltext): 
    posList = data_list.curselection() 
    if not posList: # exit if nothing selected 
     return 

    for pos in posList: 
     if pos == 0: 
      my_status_update('Item at top of list.') 
      continue 
     text = data_list.get(pos) 
     data_list.delete(pos) 
     data_list.insert(pos -1, text) 
# new, doesn't work - [from here][4]. 
#  data_list.selection_clear() 
     data_list.selection_set(pos) 
    return 

回答

0

使用activate(index)就可以了。这会将给定索引处的项目设置为活动项目(给它下划线)。

data_list.activate(pos -1) 

您还需要添加-1为selection_set以及

data_list.selection_set(pos -1) 
+0

甜!非常感谢!! – shawn