How can I use the same callback function to trace multiple variables?

。_饼干妹妹 提交于 2019-12-02 10:07:30

You can send the key and the input to the function. This is a truncated version and a little different than your code but does what I think you want.

import tkinter as tk
from functools import partial

def callback(key, var, *args):
    print "callback var =", key, var.get()
    ##myStrVars[key].set(var[-1])

root = tk.Tk()

for key in range(5):
    var = tk.StringVar()
    var.trace('w', partial(callback, key, var))
    tk.Entry(root, textvariable=var).pack()

root.mainloop()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!