Skip to content Skip to sidebar Skip to footer

How To Pass More Arguments Through Tkinter Bind

How do I pass more arguments through tkinter's bind method? for the example: tk = Tk() def moveShip(event,key): if event.keysym == 'Down' and player1.selectedCoord[1] != 9:

Solution 1:

You can always wrap the callback function in a lambda.

tk.bind('<Key>', lambda event: moveShip(event, 'place'))

The other option is to use partial from functool to create a function with the default value of key already set.

from functools import partial

moveShip_place = partial(moveShip, key='place')

tk.bind('<Key>', moveShip_place)

Post a Comment for "How To Pass More Arguments Through Tkinter Bind"