I'm trying to refactor some code here, to make it more manageable and reader-friendly. I'm currently stuck with this huge method which seems extremely simple to me, and I want to see if I can break it down any more:
def moveCircle(self, event):
if event.keysym == "Up":
self.canvas.move("circle", 0, -5)
self.canvas.move("text", 0, -5)
self.y1 -= 5
self.y2 -= 5
elif event.keysym == "Down":
self.canvas.move("circle", 0, 5)
self.canvas.move("text", 0, 5)
self.y1 += 5
self.y2 += 5
elif event.keysym == "Left":
self.canvas.move("circle", -5, 0)
self.canvas.move("text", -5, 0)
self.x1 -= 5
self.x2 -= 5
elif event.keysym == "Right":
self.canvas.move("circle", 5, 0)
self.canvas.move("text", 5, 0)
self.x1 += 5
self.x2 += 5
self.canvas.update
I've got two canvas objects, "circle" and "text" which move the same value each time a user presses one of the arrow keys. The only thing that changes is the direction (duh). My instance variables for x1, x2, y1, and y2 are used in the program for purposes not important for this question (just so you know. I do need them in-, and decremented this way). What I'm hoping for is a magical self.canvas.move("circle" && "text", 0, 5)
or something ridiculous like that. (Obviously, that command doesn't exist, but I'm wondering if there's a more concise way to do this, or if I'm just going crazy)
For the record, I also tried self.y1 = self.y2 -= 5
and the compiler threw a fit, so that was a bummer. Anyone know how to in- and decrement multiple values the same amount, at the same time? That'd be super cool beans.