Can't figure out how to bind keys in tkinter
Hello, I've been doing some research on binding keys, but I can't figure out how to, the code for the key binds is on line 24, I've tried it with and without a while loop.
Voters
Hello, I've been doing some research on binding keys, but I can't figure out how to, the code for the key binds is on line 24, I've tried it with and without a while loop.
When you
bind
a key intkinter
, you have to pass a function for it to call. Example:Notice how the handler is passed as
my_handler
, notmy_handler()
. The former passes the function itself, the latter executes the function and uses the return value (None
) as the callback.Your code passes parameters to
player.drive
, and so you will have to wrap that function call in another function with no arguments. An easy way to do that is with lambda functions:It's like a normal function, except shorter and anonymous: they are the equivalent of arrow functions in JavaScript, for example.
So, here is your code: (lines 24 and 25)
@19wintersp Ok, thanks allot! :-)