tkinter frame background image code example
Example 1: background image in python
om tkinter import *
from PIL import ImageTk
canvas = Canvas(width=600, height=800, bg='blue')
canvas.pack(expand=YES, fill=BOTH)
image = ImageTk.PhotoImage(file="File route")
canvas.create_image(10, 10, image=image, anchor=NW)
mainloop()
Example 2: python tk frame background image
from PIL import Image, ImageTk
import tkinter as tk
IMAGE_PATH = 'sfondo.png'
WIDTH, HEIGTH = 200, 200
root = tk.Tk()
root.geometry('{}x{}'.format(WIDTH, HEIGTH))
canvas = tk.Canvas(root, width=WIDTH, height=HEIGTH)
canvas.pack()
img = ImageTk.PhotoImage(Image.open(IMAGE_PATH).resize((WIDTH, HEIGTH), Image.ANTIALIAS))
canvas.background = img
bg = canvas.create_image(0, 0, anchor=tk.NW, image=img)
button = tk.Button(root, text="Start")
button_window = canvas.create_window(10, 10, anchor=tk.NW, window=button)
root.mainloop()