When displaying a background image using tkinter When I displayed it using Canvas, a white frame was included as shown in the image on the left. I didn't like that, so I will describe how to display it in the entire window as shown in the image on the right.
Windows10 64bit Python 3.6.9 tkinter 8.6
Use Label to display the image.
Image used (256x256)
When using Label(Displayed throughout)
import tkinter as tk
#Creating a window
root = tk.Tk()
root.title("Test")
root.geometry("256x256")
#Browse file
background = tk.PhotoImage(file="Lenna.png ")
#Creating a Label
bg = tk.Label(root, image=background)
bg.pack(fill="x")
#Window drawing
root.mainloop()
Because there was a white frame when displaying using Canvas It was to display using Label. If you know how to erase the Canvas frame or other efficient methods I would appreciate it if you could teach me.
Recommended Posts