Dec-08-2016, 09:56 PM
This one;
def movesquare(event): # detect movement keys if event.keysym == "Up": canvas.move(SQident, 0, -50) elif event.keysym == "Down": canvas.move(SQident, 0, 50) elif event.keysym == "Left": canvas.move(SQident, -50, 0) elif event.keysym == "Right": canvas.move(SQident, 50, 0)is begging for a dictionary:
moves={'Up':(0, -50),'Down':(0,50), 'Left':(-50,0), 'Right':(50,0)} def movesquare(event): # detect movement keys x,y=moves[event.keysym] canvas.move(SQident,x,y)There is even a way to replace the whole function by a one-liner but this can make the code a bit less readable.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Your one-stop place for all your GIMP needs: gimp-forum.net