I want to change the text label on a canvas when buttons are clicked. I want to increase the label by 10 if the button \"up\" is clicked and decrease by 10 if the button \"down\
You can use the documented itemconfigure
method of the canvas to change any configuration option of any object on the canvas.
For example, you could write a method named change_consumption
that takes a parameter for how much to change the value by, and it can use itemconfigure
to change what appears on the canvas:
def change_consumption(self, amount):
self.consumption += amount
self.canvas.itemconfigure(self.cons, text=self.consumption)
You would bind to this function like this for the "up" button; for "down" you would pass -10
:
self.but.bind("", lambda event: self.change_consumption(10))