Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter & Canvas
#6
CPython uses a reference count to determine when objects are no longer used, and their memory can be recycled. If nothing references an object. there is nothing you can do with the object, so it must be unused.

In your program you used a local variable to reference the image returned by tkinter.PhotoImage(). When you left the function (Guess.__init__() for example) all the local variables cease to exist. There is nothing left to reference the image, so the image is deleted and the memory recycled. By changing image from a local function variable to an instance variable your program keeps a reference to the image.
Reply


Messages In This Thread
Tkinter & Canvas - by Peter_Emp1 - Mar-23-2024, 01:11 PM
RE: Tkinter & Canvas - by menator01 - Mar-23-2024, 09:41 PM
RE: Tkinter & Canvas - by deanhystad - Mar-24-2024, 02:42 AM
RE: Tkinter & Canvas - by Peter_Emp1 - Mar-24-2024, 07:13 PM
RE: Tkinter & Canvas - by Pedroski55 - Mar-24-2024, 06:25 PM
RE: Tkinter & Canvas - by deanhystad - Mar-24-2024, 07:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to positon a tkinter canvas Tyrel 3 1,998 Dec-11-2020, 03:05 PM
Last Post: deanhystad
  use classes in tkinter canvas fardin 2 2,718 Jan-06-2019, 04:23 AM
Last Post: fardin

Forum Jump:

User Panel Messages

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