简体   繁体   中英

Image not showing (tkinter in python)

When I try to insert the image into my Tkinter window all that shows up is this

import tkinter as tk
root = tk.Tk()
root.title("To Do List")
canvas = tk.Canvas(root, height=900, width=1000, bg='white')
frame = tk.Frame(root, bg="#000000")
img = tk.PhotoImage("deathnote.png")
entry = tk.Entry(frame, font='system', fg='white', bg='black')
imglabel = tk.Label(frame, image=img)
canvas.grid(row=0, column=0)
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
imglabel.grid(row=0, column=2)
entry.grid(row=1, column=1)


root.mainloop()

Try using PIL:

import tkinter as tk
from PIL import ImageTk, Image

root = tk.Tk()
root.title("To Do List")
canvas = tk.Canvas(root, height=900, width=1000, bg='white')
frame = tk.Frame(root, bg="#000000")
img = ImageTk.PhotoImage(Image.open("deathnote.png"))
entry = tk.Entry(frame, font='system', fg='white', bg='black')
imglabel = tk.Label(frame, image=img)
canvas.grid(row=0, column=0)
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
imglabel.grid(row=0, column=2)
entry.grid(row=1, column=1)


root.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM