Reputation: 15
I want to have the button's image cycle through all possible pizza images, but instead it throws the following error when I click on it:
self.config(image=next(self.images))
AttributeError: 'buttonInitialize' object has no attribute 'config'
Here's the code. I know it's ugly, sorry. I barely understand python classes, so I couldn't figure out how to factor the repetitive parts out
from tkinter import *
from itertools import cycle
class buttonInitialize:
def __init__ (self,enabler):
frame=Frame(enabler)
frame.pack()
pizzaList=[]
pizzaList.append(PhotoImage(file="Cheese.png").zoom(10))
pizzaList.append(PhotoImage(file="AvocadoWSauce.png").zoom(10))
pizzaList.append(PhotoImage(file="AvocadoWCheese.png").zoom(10))
self.images=cycle(pizzaList)
self.printButton=Button(frame,image=pizzaList[0] ,command=self.nextPizza)
self.printButton.pack(side=LEFT)
def nextPizza(self):
self.config(image=next(self.images))
root=Tk()
c=buttonInitialize(root)
root.mainloop()
Upvotes: 0
Views: 728