【问题标题】:move tkinter listbox curser with item being shifted?移动 tkinter 列表框光标并移动项目?
【发布时间】:2016-03-28 03:01:15
【问题描述】:

使用 Tkinter 运行 python 2.7.8。我有一个移动列表框项目的功能。此功能有效。但是,我还想移动列表框选择(即,正在移动的东西的指示器)。

我的班次函数基于this thread。 这是之前的清单: before_shift_function 并在调用函数后: after_shift_function

如何将选择“从属于”我的班次?谢谢

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

【问题讨论】:

    标签: python-2.7 select tkinter listbox


    【解决方案1】:

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

    data_list.activate(pos -1)
    

    您还需要为 selection_set 添加-1

    data_list.selection_set(pos -1)
    

    【讨论】:

    • 甜蜜!非常感谢!!
    猜你喜欢
    • 1970-01-01
    • 2018-09-04
    • 2018-12-24
    • 2023-03-07
    • 2010-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多