I have simple code like this:
from tkinter import *
def _show_value(*pargs):
print(*pargs)
root = Tk()
entry_var1 = StringVar()
entry_var1.trace(\'w\'
You can do it in two ways.
First, use globalgetvar
method of your root window.
def _show_value(*pargs):
print(*pargs)
print(root.globalgetvar(pargs[0]))
This, should give you text of respective entry.
Second, and probably more recommended is to pass StringVar
references into _show_value
, using lambdas
for instance, rather then using global variables of Tk:
from tkinter import *
def _show_value(v, *pargs):
print(*pargs)
print(v.get())
root = Tk()
entry_var1 = StringVar()
entry_var1.trace('w', lambda *pargs: _show_value(entry_var1, *pargs))
entry_var2 = StringVar()
entry_var2.trace('w', lambda *pargs: _show_value(entry_var2, *pargs))
e1 = Entry(root, textvariable=entry_var1)
e1.pack()
e2 = Entry(root, textvariable=entry_var2)
e2.pack()
root.mainloop()