2015-12-21 83 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