Мне удалось изменить значение переменной на новое изображение, но оно не отображается в графическом интерфейсе (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