1. You are right -
2.
3. Looking at the error traceback, when you try to create
4. Looking at the tkinter code,
5. without
6. That is the first error you get
7. However because there is no
I am not using tkinter, so I was not familiar with
ImageTk
is PIL/Pillow class2.
PIL.ImageTk
is convenient wrapper around tkinter.PhotoImage
class3. Looking at the error traceback, when you try to create
ImageTk
instance, it try to instantiate object of tkinter.PhotoImage
class and assign it to __photo
attribute of PIL.ImageTk
object.4. Looking at the tkinter code,
tkinter.PhotoImage
in turn inherits from tkinter.Image
class. tkinter.Image.__init__()
method needs master
attribute. That is the parent widget of the tkinter.Image
. If you don't explicitly pass one, it search for default one - available tkinter.Tk() instance.5. without
root = tk.Tk()
there is no Tk() instance in your program and it fails6. That is the first error you get
RuntimeError: Too early to create image
which is "ignored"7. However because there is no
self.__photo
- you get the next AttributeError
.I am not using tkinter, so I was not familiar with
PIL.ImageTk
. It was not clear in the docs that it's a wrapper. So my previous statement that there should not be a problem was not correct, i.e. I learned something new
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs