Image does not appear on Tkinter

后端 未结 1 680
误落风尘
误落风尘 2021-01-29 01:35

l have an problem with Tkinter as l would like to add an image as background of frame ,however ,l tried many things but nothing show up. l m at the beginning of my

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 02:32

    The problem is that your filename isn't being treated as the filename of the image. The first non-keyword argument is used as the internal name of the image.

    You must specify the file keyword argument for it to use the file as the image:

    img=PhotoImage(file="mat.png")
    

    Also, depending on what version you have installed, tkinter may not support png files. If your system does not, with the above change you'll get at error like TclError: couldn't recognize image data. If that is the case, you'll need to convert your image to GIF.

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