tkinter canvas image is not displayed in class

前端 未结 1 1027
梦谈多话
梦谈多话 2020-12-18 05:52

I am trying to display an image in python using the tkinter canvas option. However, if I input it in a class, like below, it doesn\'t give an error but also doesn\'t show my

1条回答
  •  执念已碎
    2020-12-18 06:36

    You have to keep a reference to the PhotoImage. This is just and example (you can also use self.background instead of c.background):

        c = Canvas(frame2)
        c.pack(expand=YES,fill=BOTH)
        c.background = PhotoImage(file='Board.gif')
        c.create_image(100,100,image=c.background,anchor='nw')
    

    0 讨论(0)
提交回复
热议问题