鱼C论坛

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

tkinter 组件绑定事件问题

[复制链接]
发表于 2018-7-1 11:19:25 | 显示全部楼层 |阅读模式
20鱼币
问题代码如下,网上看的代码,不是很懂
  1. #coding=utf-8

  2. import Tkinter

  3. def handler(event, a, b, c):
  4.         print (event)
  5.         print ("handler", a, b, c)

  6. def handlerAdaptor(fun, **kwds):
  7.         '''[color=Red]这里的event是个假参数吗,只是为了后面多个参数传递而存在吗[/color]'''
  8.         return lambda event,fun=fun,kwds=kwds: fun(event, **kwds)

  9. if __name__=='__main__':
  10.         root = Tkinter.Tk()
  11.         btn = Tkinter.Button(text=u'按钮')

  12.         # 通过中介函数handlerAdaptor进行事件绑定
  13.         btn.bind("<Button-1>", handlerAdaptor(handler, a=1, b=2, c=3))

  14.         btn.pack()
  15.         root.mainloop()
复制代码

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

使用道具 举报

发表于 2018-7-1 20:50:22 | 显示全部楼层
不是假参数,不然handler也打印不出event
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-12-31 12:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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