_tkinter.TclError: image “…” doesn't exist

前端 未结 3 1060
囚心锁ツ
囚心锁ツ 2020-12-02 00:07

I know that this question has already been asked several times, but I still couldn\'t figure out the answer to my problem. I keep getting the same error and don\'t know how

相关标签:
3条回答
  • 2020-12-02 00:53

    You should use PhotoImage instance as image value. Also, you need to keep the reference of your image.

    im = Image.open(pathToImage)
    ph = ImageTk.PhotoImage(im)
    
    label = Label(window, image=ph)
    label.image=ph  #need to keep the reference of your image to avoid garbage collection
    
    0 讨论(0)
  • 2020-12-02 00:54

    It seems to be an Anaconda - Spyder - Iphyton problem. Solution is here: _tkinter.TclError: image "pyimage" doesn't exist

    0 讨论(0)
  • 2020-12-02 00:56

    A quick hacky fix is to provide the PhotoImage with the correct master:

    i = ImageTk.PhotoImage(pathToImage, master=window)
    
    0 讨论(0)
提交回复
热议问题