Dec-09-2016, 11:03 AM
Quote:I guess I could implement that but the +/- 50 also corresponds to the size of the square (not speed).It was more of a generic concept related to reducing magic numbers in code.
Define speed in one place and the dict never changes. If you need to change speed you change it in one place.
Something to keep in mind in the future.
As to your question, I don't use tkinter much, but yes.
You could do something like this:
bindings = {"<KeyPress-Up>" : movesquare, "<KeyPress-Down>": movesquare, "<KeyPress-Left>": movesquare, "<KeyPress-Right>": movesquare, "x": otherkey, "f": otherkey, "r": otherkey} for binding in bindings: canvas.bind_all(binding, bindings[binding])Also, I question whether or not you need to rebind those every time through the loop.
Once up front should be fine I would think.