python - Why does this code work only with *args in something()? -
would mind taking minute explain why code works when give something() parameter *args? seems though should work without because being called without arguments... stumped..
from tkinter import * mgui = tk() mgui.geometry('570x130+700+200') mgui.resizable(width = false, height = false) mgui.title('title') def something(*args): if somevalue.get() == 'tom': mlabel2.lift() else: mlabel2.lower() mylist = ['henry', 'tom', 'phil'] somevalue = stringvar() somevalue.trace('w', something) mlabel = label(text = ' name:') mlabel.grid(row = 0, column = 0, sticky = e) mlabel2 = label(text = 'success') mlabel2.grid(row = 0, column = 0, sticky = e) mlabel2.lower() somemenu = optionmenu(mgui, somevalue, *mylist) somemenu.grid(row = 0, column = 1, sticky = w) somemenu.config(width = 14, anchor = w) mgui.mainloop()
**edit, program initialize, select value somemenu throws out typeerror: something() takes no arguments (3 given)
the callback function trace
called 3 argument: name1
, name2
, op
according tcl trace
documentation.
so callback function should following form:
def callback(name1, name2, op): pass
but, in question code, something
not use of parameters. function use abitrary argument list (*args
) implicitly ignore them.
Comments
Post a Comment