Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how the class works
#8
1. You are right - ImageTk is PIL/Pillow class
2. PIL.ImageTk is convenient wrapper around tkinter.PhotoImage class
3. 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 fails
6. 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

Reply


Messages In This Thread
how the class works - by berckut72 - Mar-16-2020, 06:38 PM
RE: how the class works - by buran - Mar-16-2020, 06:45 PM
RE: how the class works - by berckut72 - Mar-16-2020, 06:48 PM
RE: how the class works - by buran - Mar-16-2020, 06:52 PM
RE: how the class works - by berckut72 - Mar-16-2020, 06:57 PM
RE: how the class works - by buran - Mar-16-2020, 09:43 PM
RE: how the class works - by berckut72 - Mar-17-2020, 05:04 AM
RE: how the class works - by buran - Mar-17-2020, 06:31 AM
RE: how the class works - by berckut72 - Mar-17-2020, 09:54 AM
RE: how the class works - by buran - Mar-17-2020, 09:56 AM
RE: how the class works - by berckut72 - Mar-17-2020, 10:03 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020