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