Python 将事件/命令绑定到列表框中的项目(使用滚动条)
我正在制作一个程序,在这个程序中可以创建任意数量的用户,要选择一个,你必须点击他们的名字,这个名字包含在一个可滚动的列表框中是否有任何方式(绑定或其他方式)在单击列表框中的不同项目时执行命令?Python 将事件/命令绑定到列表框中的项目(使用滚动条),python,tkinter,listbox,Python,Tkinter,Listbox,我正在制作一个程序,在这个程序中可以创建任意数量的用户,要选择一个,你必须点击他们的名字,这个名字包含在一个可滚动的列表框中是否有任何方式(绑定或其他方式)在单击列表框中的不同项目时执行命令?def onselect(evt): def onselect(evt): # Note here that Tkinter passes an event object to onselect() w = evt.widget index = int(w.curselection()[0]) value
def onselect(evt):
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)
#请注意,Tkinter将事件对象传递给onselect()
w=evt.widget
index=int(w.curselection()[0])
值=w.get(索引)
打印“您选择的项目%d:“%s”%”(索引,值)
lb=Listbox(frame,name='lb')
lb.bind(“”,onselect)
我在帖子的评论中提到了这一点,其中包含了上面的答案。好了,现在有个问题,我有点忘了提出来。请提供一个列表框缺少所需行为的基本示例。