鱼C论坛

 找回密码
 立即注册
查看: 3507|回复: 2

tkinter listbox 条目删除问题。

[复制链接]
发表于 2017-12-13 19:19:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
tkinter 里面的 listbox,模式设置成EXTENDED以后能多选,但是删除的时候还是只能删除一个呀,删除ACTIVE的时候 还是只删除了一个。
怎么能一次删除选中的呢?

代码如下:

from tkinter import *

root = Tk()

theLB = Listbox(root,selectmode = EXTENDED)
theLB.pack()

for item in ['egg', 'chicken','dog']:
    theLB.insert(END, item)



theButton = Button(root, text='delete it', \
                   command = lambda x=theLB: x.delete(ACTIVE))

theButton.pack()


mainloop()
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-12-13 21:20:08 | 显示全部楼层
theButton = Button(root, text='delete it', \
                   command = lambda x=theLB: x.delete(x.curselection()[0], x.curselection()[-1]))
ACTIVE 是表示激活的项目,下面会有条下划线
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-14 16:04:41 | 显示全部楼层
ba21 发表于 2017-12-13 21:20
theButton = Button(root, text='delete it', \
                   command = lambda x=theLB: x.delete( ...

理解了~   多谢~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-3-22 13:59

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表