Python Forum

Full Version: moniter which widget triggerd event
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I use tkinter and have several entries
now i'm using
to monitor event,
Q:can this function func tell me which entry had been changed and point a variable to it like:
def func():
    pointer={an entry that has been changed}
Thank you!!!
Please post a snippet that we can be run.
the problem is I dont really know if there is this function to focus on the entry changed, this is the closest i can give:
import tkinter as tk
def func(var):
    print('the following one is the problem, i dont know if it has this function')
    #pointer={an entry that has been changed}
in the bind statement, <key> needs to be replaced with what you want to bind to,
and func needs to be replaces with the name of a function that you want to run when the event occurs.
Since you are not using a class, the 'func' must be defined with a 'def' prior to the bind statement which you have done.
you need to capture the event as an attribute of 'func' (I'd choose a better name here) and finally
the bind must be for a widget, not a window

assume you wanted to use left mouse button to bind to Entry a when enter button is pressed, the statement should look like:
a.bind('<Return>', func)
I actually want to monitor any key event, and on any entry in the window, that why i used '<Key>' and window.bind()
the purpose is to run a parameter assignment function whenever there are values(in the entry) changed. But there are different functions when some special entries changed, thats why i need to know which entry changed.
OK, misunderstood.
see example here:
section: Capturing keyboard events