【发布时间】:2011-01-09 16:06:46
【问题描述】:
我是 tkinter 的新手,所以我是初学者.. 我需要帮助,因为我正在尝试对井字游戏进行编程.. 我想以心形按钮作为区域开始游戏,当玩家点击该图像时X 或 O 的变化(另一个 gif 图像)... 所以我需要一个函数来帮助我切换按钮中的图像但是当我尝试这样做时它给了我这个错误: AttributeError: 'Button' object has no attribute 'image' 这是给我问题的代码部分..
class Application(object):
def __init__(self,fnt2):
self.photo = PhotoImage(file="game.gif")
self.lab1 = Label(fnt2, text="WELCOME to the GAME")
self.lab1.image = self.photo
self.lab1['background']="#BD5151"
self.lab1['foreground']="#651268"
self.lab1.image = self.photo
self.lab1.pack()
self.lab2= Label(image=self.photo)
self.lab2.image= self.photo
self.lab2['background']="#BD5151"
self.lab2.pack()
self.imm0 = PhotoImage(file="start.gif")
self.imm1 = PhotoImage(file="bianco.gif")
self.imm2 = PhotoImage(file="ics.gif")
self.Ent = Button(fnt2, text="Click To Enter The GAME")
self.Ent['relief']="groove"
self.Ent['command']=self.Ent_Click
self.Ent.pack()
def Changepic_1(self):
imm0 = PhotoImage(file="start.gif")
imm1 = PhotoImage(file="bianco.gif")
imm2 = PhotoImage(file="ics.gif")
if self.Play.image == self.imm0:
print('ciao')
def Ent_Click(self):
fnt2 = Tk()
fnt2.title("play it!")
fnt2.resizable(False,False)
for r in range(3):
for c in range(3):
self.Play = Button(image = self.imm0, command=self.Changepic_1)
self.Play.grid(row=r,column=c)
fnt2.mainloop()
【问题讨论】: