简体   繁体   中英

Python PIL cant put a image on a tkinter window

Im trying to put a image in a tkinter window with this code...

from tkinter import *
from PIL import ImageTk, Image

root = Tk

my_img = ImageTk.PhotoImage(Image.open("Imagem1.png"))
MyLabel = Label(root, image=my_img)
MyLabel.pack()

root.mainloop()

But it keeps getting this error "name 'PhotoImage' is not defined"

You have a error at root=Tk -> root=Tk()

from tkinter import *
from PIL import ImageTk, Image

root = Tk()

my_img = ImageTk.PhotoImage(Image.open("Image1.png"))
MyLabel = Label(root, image=my_img)
MyLabel.pack()

root.mainloop()

Output: 在此处输入图像描述

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