1

i`m a student to study python few days ago, and i interested in 'tkinter' nowadays.

i have no idea where is wrong in that code and error message below.

please help me..TT

# -*- coding: utf-8 -*-
import tkinter as tk

banana=r'banana.gif'
bodercolor=[('aliceblue','#F0F8FF'),('blue','#000FF'),
             ('beige','#F5F5DC'),('cornsilk','#FFF8DC'),
              ('red','#ff0000'),('lightgreen','#90EE90')]

class BgChange:
    def __init__(self, label, color):   
        self.label = label
        self.color = color

    def __call__(self, event=None):
        self.label.configure(bg=self.color)

class MyWindow(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.master.title('select bordercolor')
        f_button=tk.Frame(self)
        f_button.pack(side=tk.LEFT, padx=5, pady=1)
        self.banana=tk.PhotoImage(file = banana)     
        label=tk.Label(self, image=self.banana,relief=tk.RAISED, bd=6)
        label.pack(side=tk.RIGHT,padx=7)

        for name, code in bodercolor:
            b=tk.Button(f_button, text=name,
                        bg=code, command=BgChange()) 
            b.pack(fill=tk.X)

if __name__== '__main__':
    MyWindow(tk.Tk()).mainloop()

Error message

runfile('C:/Users/User/Desktop/python_ex/report/문제2.py', wdir='C:/Users/User/Desktop/python_ex/report')
Traceback (most recent call last):

  File "<ipython-input-14-8a31f2388234>", line 1, in <module>
    runfile('C:/Users/User/Desktop/python_ex/report/문제2.py', wdir='C:/Users/User/Desktop/python_ex/report')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/User/Desktop/python_ex/report/문제2.py", line 35, in <module>
    win = MyWindow(root)

  File "C:/Users/User/Desktop/python_ex/report/문제2.py", line 24, in __init__
    label=tk.Label(self, image=self.banana,relief=tk.RAISED, bd=6)

  File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 2766, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)

  File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 2299, in __init__
    (widgetName, self._w) + extra + self._options(cnf))

TclError: image "pyimage10" doesn't exist
1
  • 1
    ``` File "<ipython-input-2-5dcb34d10bfd>", line 35, in <module> MyWindow(tk.Tk()).mainloop() File "<ipython-input-2-5dcb34d10bfd>", line 24, in init label=tk.Label(self, image=self.banana,relief=tk.RAISED, bd=6) File "C:\ProgramData\Anaconda3\lib\tkinter_init_.py", line 2766, in init Widget.__init__(self, master, 'label', cnf, kw) File "C:\ProgramData\Anaconda3\lib\tkinter_init_.py", line 2299, in init (widgetName, self._w) + extra + self._options(cnf)) TclError: image "pyimage2" doesn't exist ``` Commented Nov 18, 2019 at 2:40

2 Answers 2

1

Welcome to Stackoverflow. You should provide a Minimal Reproducible Example

According to your error:

TclError: image "pyimage10" doesn't exist

I provide the full\absolute path which is in my case

self.banana='C:\\Users\\Python\\banana.gif'

I also keep a reference to the image:

self.master.banana= PhotoImage(file = self.banana) 

Here the complete code:

# -*- coding: utf-8 -*-
from tkinter import Tk, Label, Frame, PhotoImage

class MyWindow():
    def __init__(self, master=None):
        self.banana='C:\\Users\\Python\\banana.gif'
        self.master = master
        self.master.title('select bordercolor')

        self.f_button = Frame(self.master)
        self.f_button.pack(side= "left", padx=5, pady=1)
        self.master.banana= PhotoImage(file = self.banana) 

        self.label= Label(self.master, image=self.master.banana, relief="raised", bd=6)
        self.label.pack(side="right", padx=7)

if __name__== '__main__':
    root = Tk()
    MyWindow(root)
    root.mainloop()

You have other errors in your code but this is an other question worth. See tkinter command option in buttons!

Sign up to request clarification or add additional context in comments.

2 Comments

reaaaally appreciate your advice! i`ll try it, thank you!
please set this question as answered if that solve your problem
0

I was working with tkinter and found the same error but interestingly i notice a pattern like some time it work and sometime it show this error!

the easy fix for this is run this code first :

import tkinter as tk

root = tk.TK()

root.mainloop()

after that is will show more than one Tkinter windows just close all and then run your code FROM START I.E FROM IMPORTING THE LIBRAIRES AGAIN AND THEN RUNNING THE CODE.

I hope this will fix the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.