'Passing object in virtual generated event with tkinter
I'm trying to create virtual event and pass data in the event object in tkinter.
This is my code:
def func(self, event)
print(event.data) #AttributeError: 'Event' object has no attribute 'data'
self.bind('<<test>>', func)
...
...
self.event_generate('<<test>>', data = "test_obj")
I get the following error when running the code:
AttributeError: 'Event' object has no attribute 'data'"
If data field is not supported anymore, How can I pass data using the event object?
def func(self, event)
print(dir(event))
output (no data field):
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'char', 'delta', 'height', 'keycode', 'keysym', 'keysym_num', 'num', 'send_event', 'serial', 'state', 'time', 'type', 'widget', 'width', 'x', 'x_root', 'y', 'y_root']
however event_generate can accept data field (please ignore the error):
_tkinter.TclError: bad option "-num": must be -when, -above, -borderwidth, -button, -count, -data, -delta, -detail, -focus, -height, -keycode, -keysym, -mode, -override, -place, -root, -rootx, -rooty, -sendevent, -serial, -state, -subwindow, -time, -warp, -width, -window, -x, or -y
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
