Python将变量刷新为新值tkinter

时间:2019-03-04 12:12:22

标签: python variables tkinter refresh

我设法将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

1 个答案:

答案 0 :(得分:0)

您要搜索的方法是canvas.update() :(很明显)它将应用所有修改并激活已触发的绑定函数。