Python Forum

Full Version: Having trouble using photo for background
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Just wondering what I am doing wrong. I have a photo named overlander_sports.jpg in the newb folder which is the name of the project. I can't seem to get it as a background.

from tkinter import *
import datetime
from tkinter import messagebox

root = Tk()
#Date and Time

C = Canvas(root, bg="blue", height=250, width=300)
filename = PhotoImage(file="C:\\Users\\blake\PycharmProjects\\newb\\overlander_sports.jpg")

background_label = Label(root, image=overlander_sports.jpg)
background_label.place(x=0, y=0, relwidth=1, relheight=1)

C.pack()
change the background_label line to reference the "filename" variable
that you set in previous line.

background_label = Label(root, image=filename)

Also you can't read a jpg file with this method
you would need to use the Pillow add-on,
But you can still read in a gif or png with this code.
Great thank you!