I am trying to create a weather App in Tkinter GUI. It is working fine. I want to add a background image to it but it wont show up. initially i did it without the reference line but it didnt work. On some website they said to keep reference of the image but that too didnt work. Also my Tkinter window size is 1920x1080 and the image was of same dimension but it still doesnt show up. I tried to reduce image size than window but still not working. Any suggestions accepted. Also there is no error.
bg = PhotoImage('clearsky2.jpg')
bgl = Label(gui,image=bg)
bgl.image = bg #given a reference
bgl.place(x=0, y=0, relwidth=1,relheight=1)
bgl.pack()
Its sad that
tkinter.PhotoImagedoes not supportJPEGfiles, but it does supportPNGin the newer version and has proper support forGIFtoo. To useJPEGyou needPILinstalled. In the terminal say:After that import it like:
Then now, to open the image with PIL, say:
This will work with
JPEGandPNGfiles as well and, keep in mind you dont need to keep a reference unless your looping over images or creating image inside of a function.Hope it cleared your problem, do let me know if any more errors
Cheers