鱼C论坛

 找回密码
 立即注册
查看: 2081|回复: 1

l小甲鱼Tkinter教程代码中的一个疑问

[复制链接]
发表于 2019-11-15 15:46:07 | 显示全部楼层 |阅读模式

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

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

x
这是源代码:


from tkinter import *

root = Tk()

theLB = Listbox(root, setgrid=True)
theLB.pack()

for item in ['蜘蛛侠', '钢铁侠', '绿巨人', '黑寡妇']:
    theLB.insert(END, item)

theButton = Button(root, text='删除', command=lambda x=theLB:x.delete(ACTIVE))
theButton.pack()

mainloop()


在  command=lambda x=theLB:x.delete(ACTIVE)这里,写成command = theLB.delete,Button按键无效果
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-11-15 18:59:25 | 显示全部楼层
Tkinter 内部调用 command 方法不会传参数,所以当按下 Button 时会这样调用:theLB.delete(),都没传参,肯定无效果。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-20 18:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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