Source Code for set set background image in tkinter
make sure that you have already installed tkinter.
Let's copy this code and run with Python.
#coding with sayed
#import tkinter
from tkinter import *
from PIL import ImageTk,Image
root=Tk()
#set width and height
canvas=Canvas(root,width=300,height=160)
#give this image path. image should be in png format.
#Example: "C:\\Users\\ASUS\\OneDrive\\Pictures\\image.png"
image=ImageTk.PhotoImage(Image.open("your_image_path"))
canvas.create_image(0,0,anchor=NW,image=image)
canvas.pack()
root.mainloop()
#import tkinter
from tkinter import *
from PIL import ImageTk,Image
root=Tk()
#set width and height
canvas=Canvas(root,width=300,height=160)
#give this image path. image should be in png format.
#Example: "C:\\Users\\ASUS\\OneDrive\\Pictures\\image.png"
image=ImageTk.PhotoImage(Image.open("your_image_path"))
canvas.create_image(0,0,anchor=NW,image=image)
canvas.pack()
root.mainloop()
happy coding...
I have done this and it works, but when I add a button with .grid(row=0,column=0) it doesnt show up. Do you know how I can correct this?
ReplyDeleteu have to change the grid on the canvas part since you cant use grid and pack at the same time
ReplyDelete