1

I would like to know what each of the commands after lambda in this line of code is for and its purpose. It doesn't make sense to me on why its there:

sv.trace("w", lambda name, index, mode, sv=sv: self.NameLimit(sv))

I have got the validation to work how i want but don't know what name, index, mode, sv=sv is for.

I have to understand it to use it in my code as that is very important. I don't need a super detailed explanation (although it would be ok) but just an overview of what each lambda argument does. Thanks :)

Example code with this in use:

from tkinter import *
from tkinter import ttk
import random
def main():
    pass

if __name__ == '__main__':
    main()



def callback(sv):
    c = sv.get()[0:9]
    print ("c=", c)
    sv.set(c)

root = Tk()
sv = StringVar()
sv.trace("w", lambda name, index, mode, sv=sv: callback(sv))
e = Entry(root, textvariable=sv)
e.pack()
root.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • sv is a string variable from my tkinter entry widget. I am using self.NameLimit(sv) as a callback that limits the character input to 10 characters. – Tweakforce_LG Apr 20 '17 at 10:17
  • Hm, could not find details on the parameters expected by `trace`, either. You should add some more context to the question, though. Where did you get that code from? Maybe there's some explanation there that you missed. – tobias_k Apr 20 '17 at 10:29
  • Here is the full example code i followed. ill put it in the original post. – Tweakforce_LG Apr 20 '17 at 10:31
  • I also went back to the place i got the code from and there is no obvious reason to the arguments. Thanks for the help by the way – Tweakforce_LG Apr 20 '17 at 10:33

0 Answers0