我被python GUI卡住了。我想从filedirector将图像传输到python GUI中的标签,但是此代码不起作用。图片无法显示在标签中。如何解决?
import os
import tkinter as tk
from tkinter import filedialog,image_names,image_types
root = tk.Tk()
images=[]
def addImage():
openFile.image = filedialog.askopenfile(initialdir="/",title="select image",
for image in images:
label=tk.Label(fr1,image=openFile,bg="gray")
label.pack()
from PIL import Image,ImageTk
您的代码应如下所示:
`width = 50
height = 50
load = Image.open('my_image.png')
load = load.resize((width,height), Image.ANTIALIAS)
render = ImageTk.PhotoImage(load)
img = Label(root, image=render)
img.image = render
img.place(x=50,y=50)`
显然,您的宽度和高度将与此处的示例不同,并且图像的位置也会有所不同。希望对您有所帮助