图像未在Python TkInter中显示。我做错什么了?

2024-09-19 23:37:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码:

...

recomlist = []
class recomclass:
        def recomfunc(self,a,b,c,d):
                self.recomphoto = PhotoImage(file=a)
                self.recomphotolabel = Button(bottompanel, image=self.recomphoto, width=463, height=293)
                recomphotolabel.grid(column=b)
                global recomlist
                recomlist += [a]


                self.recomname = Label(bottompanel, text=c, bg="red4", fg="white", font=("Arial", 30))
                self.recomname.place(x=d, y=255)


sobarecom = recomclass()
risottorecom = recomclass()
lasagnerecom = recomclass()


sobarecom.recomfunc("Soba Noodles.ppm", 0, "Soba Noodles", 0)
risottorecom.recomfunc("Mushroom Risotto.ppm", 1, "Mushroom Risotto", 463)
lasagnerecom.recomfunc("Pizza.ppm", 2, "Lasagne", 926)

...

它不显示这三幅图像,而是只显示第一幅,另外两幅显示白色背景。我做错了什么?我该怎么解决这个问题

非常感谢


Tags: selfppmnoodlesmushroombottompanelrecomclassrecomphotosobarecom