#!/usr/bin/python3
from Tkinter import *
def keypress(key):
print key, "pressed"
if __name__ == '__main__':
root = Tk()
root.bind('<Return>', keypress(key="enter"))
root.bind('a', keypress(key="a"))
root.mainloop()
I realize the function is being called as soon as the program starts but I don't know how to pass the arguments to the keypress function without invoking it immediately. Could someone explain how to fix it?
Updated Code:
#!/usr/bin/python3
from Tkinter import *
def keypress(key):
print key, "pressed"
root = Tk()
root.bind("<Return>", lambda event: keypress(key="enter"))
root.bind("a", lambda event: keypress(key="a"))
root.mainloop()