[Python/Tkinter]如何获取在函数“event_generate"中设置的数据值? [英] [Python/Tkinter]How can I fetch the value of data which was set in function "event_generate"

查看:47
本文介绍了[Python/Tkinter]如何获取在函数“event_generate"中设置的数据值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python 2.7.4 和 Tkinter 新手,但我坚持使用以下代码.我生成了一个事件test"并使用字符串设置了data"选项,但是从事件中检索它时发生了错误.

I'm using Python 2.7.4 and new to Tkinter, and I'm stuck with the following code. I generated an event "test" and set the "data" option with a string, but an error occurred when retrieving it from event.

错误 -> AttributeError:事件实例没有属性数据"

from Tkinter import *

def handle_it(event):
    # print "event handler"
    print event.data

root = Tk()
root.after(1, lambda: root.event_generate('<<test>>', data="hi there"))
root.bind('<<test>>', handle_it)
root.mainloop()

我找不到这个案例的相关 Python 文档,所以我参考了下面的 tcl 文档http://www.tcl.tk/man/tcl8.5/TkCmd/event.htm#M14

I can't find the related Python docs for this case, so I referred to the tcl document as below http://www.tcl.tk/man/tcl8.5/TkCmd/event.htm#M14

Python 2.7 的 TKinter 是否支持数据"选项?谢谢!

Does TKinter of Python 2.7 support "data" option? Thanks!

推荐答案

不,不幸的是它没有.Tcl 解释器将其识别为有效选项,但它是事件类中未包含的缺失选项之一,例如 warp.你可以看看Tkinter源码的第1188行代码以查看其余缺少的选项.

No, unfortunately it doesn't. The Tcl interpreter recognizes it as a valid option, but it is one of the missing options that are not included in the Event class, like warp. You can take a look at the line 1188 of the Tkinter source code to see the rest of the missing options.

这篇关于[Python/Tkinter]如何获取在函数“event_generate"中设置的数据值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆