我已经设法将var的值更改为新图像,但它没有显示在GUI(tkinter)上。 想知道是否有办法刷新画布或变量以显示新图像?你知道吗
我对python很陌生,所以请对我放轻松。你知道吗
def clothesImage(self):
n = 0
def nextimage(event):
nonlocal n
while os.path.splitext(imagechange(n))[0] == os.path.splitext(getimage)[0]:
n += 1
print(imagechange(n))
# output_dir = 'resized'
def imagechange(n):
dir = os.getcwd()
ordereddir = sorted(os.listdir(dir))
getimage = ordereddir[n]
extention = os.path.splitext(getimage)[1]
while str(extention) != ".jpg":
n += 1
getimage = ordereddir[n]
extention = os.path.splitext(getimage)[1]
return getimage
getimage = imagechange(n)
width = 400
height = 533
canvas = Canvas(self, width=width, height=height)
canvas.place(x=0, y=0)
image = Image.open(getimage)
canvas.photo = ImageTk.PhotoImage(image)
image_id = canvas.create_image(width/2, height/2, anchor="center", image=canvas.photo)
canvas.bind("<Return>", nextimage)
return image_id, canvas
您正在搜索的方法是
canvas.update()
:它将(很明显)应用所有修改,并激活已触发的绑定函数。你知道吗相关问题 更多 >
编程相关推荐