Hi fellow developers I want to overlay a image over the baground that I assigned in Tkinter
is there a way to do it?
Hi and welcome.
We’ll need a little more to go on. e.g: when you say background are you referring to the color parameter bg=
in a tkinter object constructor?
The solution will also be dependent on the Geometry Management that you use.
This example should get you going. Obviously, you’ll need to re-code line 13 to point to an image on your machine.
Note: the path construction I’ve used is for a Linux distro and as such you’ll need to alter that for systems that are not Linux based.
import tkinter as tk
from tkinter import Canvas, PhotoImage, Label
root = tk.Tk()
# creat the root window
root.geometry("800x400")
root.title("Image on backGround")
root.resizable(False, False)
backGround = Canvas(root, bg="#006400", height=400, width=800)
getImage = PhotoImage(file='/home/rob/Pictures/like-19479.png')
image = Label(backGround, image=getImage)
backGround.grid()
image.place(relx=0.1, rely=0.1)
root.mainloop()
If you want a photo image as the background, use this as lines 11 – 13
backGround = Canvas(root, height=400, width=800)
getBackground = PhotoImage(file='/home/rob/Pictures/background.png')
backGround.create_image(0,0,image=getBackground)