简体   繁体   English

Python 2.7 Tkinter列表框

[英]Python 2.7 tkinter listbox

Is there any way to delete item from a listbox by its name? 有什么办法可以从列表框中删除其名称的项目? I'm trying to do something like this: 我正在尝试做这样的事情:

for name in re.findall('name\=\\"(.*?)\\\"', msg, re.DOTALL):
    listBox.delete(0, name)

but error occurred: 但发生错误:

TclError: bad listbox index "something3647": must be active, anchor, end, @x,y, or a number

Names are random. 名称是随机的。 It looks like I can insert something by its name but not delete it. 看来我可以按名称插入某些内容,但不能删除它。

No, you can't delete by name. 不,您不能按名称删除。 You can't really insert it "by name" either. 您也不能真正“按名称”插入它。 Both insertion and deletion requires an index. 插入和删除都需要索引。 However, it's only a couple lines of code to search the listbox for the item by name, and then delete the item that you found. 但是,仅需几行代码即可按名称在列表框中搜索该项目,然后删除找到的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM