Python 在tkinter列表框中选择全部

Python 在tkinter列表框中选择全部,python,tkinter,Python,Tkinter,我正在使用Tkinter和Python创建一个列表框。我想为全选创建一个按钮,但我找不到有关使用代码选择元素的任何信息 self.l = Listbox(self, height=12, selectmode=MULTIPLE) self.selectAll=Button(self, text="select all", command=self.selectAllCallback()) def selectAllCallback(self)

我正在使用Tkinter和Python创建一个
列表框。我想为
全选
创建一个按钮,但我找不到有关使用代码选择元素的任何信息

 self.l = Listbox(self, height=12, selectmode=MULTIPLE)
 self.selectAll=Button(self, text="select all",
                      command=self.selectAllCallback())
 def selectAllCallback(self)
 # What to do here
您可以将
0
END
作为参数使用(或
select\u set
)方法

例如,请尝试以下代码:

from Tkinter import *

def select_all():
    lb.select_set(0, END)

root = Tk()
lb = Listbox(root, selectmode=MULTIPLE)
for i in range(10): lb.insert(END, i)
lb.pack()
Button(root, text='select all', command=select_all).pack()
root.mainloop()
在下面的语句中,您正在调用self.selectAllCallback,而不是单击按钮绑定它。它在按钮生成之前被调用

self.selectAll=Button(self,text="select all", command=self.selectAllCallback())
                                                                            ^^
应该是:

self.selectAll=Button(self, text="select all", command=self.selectAllCallback)

我用过它,但当我点击全选时什么也没发生,什么也没突出显示,什么也没发生。谢谢,那一定很难找到。