【发布时间】:2019-03-04 12:12:22
【问题描述】:
我已经设法将 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
【问题讨论】:
标签: python variables tkinter refresh