【问题标题】:Binding events / commands to items in a listbox (with a scrollbar) [duplicate]将事件/命令绑定到列表框中的项目(带有滚动条)[重复]
【发布时间】:2018-07-01 12:30:42
【问题描述】:

我正在制作一个程序,可以在其中创建任意数量的用户,要选择一个,您必须单击其名称,该名称包含在可滚动的列表框中。 是否有任何方法(绑定或其他方式)可以在单击列表框中的不同项目时执行命令?

【问题讨论】:

  • 好的,现在有问题了,我有点忘了提出问题
  • 请提供列表框缺少您想要的行为的基本示例。

标签: python tkinter listbox


【解决方案1】:
def onselect(evt):
# Note here that Tkinter passes an event object to onselect()
w = evt.widget
index = int(w.curselection()[0])
value = w.get(index)
print 'You selected item %d: "%s"' % (index, value)

lb = Listbox(frame, name='lb')
lb.bind('<<ListboxSelect>>', onselect)

我在帖子 Getting a callback when a Tkinter Listbox selection is changed? 的 cmets 中记录了这个,其中包含上面的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 2017-09-04
    • 2014-07-30
    • 1970-01-01
    • 2010-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多