python tk frame background image

Solutions on MaxInterview for python tk frame background image by the best coders in the world

showing results for - "python tk frame background image"
Emilie
17 Mar 2017
1from PIL import Image, ImageTk
2import tkinter as tk
3
4IMAGE_PATH = 'sfondo.png'
5WIDTH, HEIGTH = 200, 200
6
7root = tk.Tk()
8root.geometry('{}x{}'.format(WIDTH, HEIGTH))
9
10canvas = tk.Canvas(root, width=WIDTH, height=HEIGTH)
11canvas.pack()
12
13img = ImageTk.PhotoImage(Image.open(IMAGE_PATH).resize((WIDTH, HEIGTH), Image.ANTIALIAS))
14canvas.background = img  # Keep a reference in case this code is put in a function.
15bg = canvas.create_image(0, 0, anchor=tk.NW, image=img)
16
17# Put a tkinter widget on the canvas.
18button = tk.Button(root, text="Start")
19button_window = canvas.create_window(10, 10, anchor=tk.NW, window=button)
20
21root.mainloop()