我希望我的代码能够将显示的比萨饼预览更改为任意披萨,但我无法弄清楚如何对其进行描述。 现在(我放大,因为我使用的小图像)从列表中更改图片tkinter
from tkinter import *
from itertools import cycle
class buttonInitialize:
def __init__ (self,enabler):
leftframe=Frame(enabler)
leftframe.pack(side=LEFT)
rightframe=Frame(enabler)
rightframe.pack(side=RIGHT)
pizzaList=[]
pizzaList.append(PhotoImage(file="0.png").zoom(10))
pizzaList.append(PhotoImage(file="1.png").zoom(10))
self.otherButton=Button(leftframe,text="??",command=self.makePizza(1))
self.otherButton.pack()
self.printButton=Button(rightframe,image=pizzaList[0])
self.printButton.pack()
def makePizza(self,index):
self.printButton["image"]=self.pizzaList[index]
root=Tk()
c=buttonInitialize(root)
root.mainloop()
,我得到了错误
AttributeError: 'buttonInitialize' object has no attribute 'pizzaList'
谢谢!
'pizzaList'不同于'self.pizzaList'。 – Lafexlos
我试过这两种方式,它仍然会抛出相同的错误。你知道我如何更新图像吗? –
添加了答案。希望,这清楚了一点。 – Lafexlos