Python Forum
Having trouble using photo for background
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having trouble using photo for background
#1
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()
Reply
#2
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.
Gribouillis likes this post
Reply
#3
Great thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  set button background with image of window background gray 3 14,353 Oct-18-2017, 08:22 AM
Last Post: gray

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020