【发布时间】:2020-07-29 03:01:27
【问题描述】:
我创建了一个简单的图像打开程序,它通过单击按钮打开从 filedialog 中选择的图像,但无论我选择另一个图像,它都会出现在当前图像下方
我希望下一张选择的图像被旧图像替换。
请帮助我该怎么办
from tkinter import *
from PIL import Image,ImageTk
from tkinter import filedialog
root=Tk()
root.title('Image')
def open():
global my_img
root.filename = filedialog.askopenfilename(initialdir='/GUI',title='Select A File',filetypes=(('jpg files','*.jpg'),('png files','*.png'),('all files','*.*')))
my_img = ImageTk.PhotoImage(Image.open(root.filename))
my_image_lbl = Label(image=my_img).pack()
my_btn = Button(root,text='Open File Manager',command=open).pack()
root.mainloop()
【问题讨论】:
标签: python python-3.x tkinter python-imaging-library tk