May-17-2020, 09:44 PM
(This post was last modified: May-17-2020, 09:44 PM by steve_shambles.)
Thank you for your reply deanhystad.
I tried your bit of code, but it doesn't seem to return a
the filenames as I would of expected, eg. pyimage1, pyimage2 etc.
instead of:
cards/gfx/FH.png
cards/gfx/FD.png
etc.
I ran the code separately to test this to make sure:
FH
FD
FC
WH
WD
WC
JH
JD
JC
JS
QH
QD
QC
QS
KH
KD
KC
KS
AH
AD
AC
AS
BH
BD
BC
pyimage1
I tried your bit of code, but it doesn't seem to return a
the filenames as I would of expected, eg. pyimage1, pyimage2 etc.
instead of:
cards/gfx/FH.png
cards/gfx/FD.png
etc.
I ran the code separately to test this to make sure:
from tkinter import Tk, PhotoImage root = Tk() spinner = ['FH', 'FD', 'FC', 'WH', 'WD', 'WC', 'JH', 'JD', 'JC', 'JS', 'QH', 'QD', 'QC', 'QS', 'KH', 'KD', 'KC', 'KS', 'AH', 'AD', 'AC', 'AS', 'BH', 'BD', 'BC'] images = [] for name in spinner: images.append(PhotoImage(file='cards/gfx/'+name+'.png')) print(name) print(images[0])output:
FH
FD
FC
WH
WD
WC
JH
JD
JC
JS
QH
QD
QC
QS
KH
KD
KC
KS
AH
AD
AC
AS
BH
BD
BC
pyimage1
(May-17-2020, 06:09 PM)deanhystad Wrote: Destroying the labels does nothing to the images. The images remain as long as their reference count is > 0. Since you keep reusing PHOTO I would expect all of your labels to display the same card. Maybe they would if set all the images first and then updated.
I do not know exactly when unreferenced objects are deleted in Python, but you are defeating it somehow.
Pre-allocating the images is easy. Easier than what you are doing now.
def make_images(): spinner = ['FH', 'FD', 'FC', 'WH', 'WD', 'WC', 'JH', 'JD', 'JC', 'JS', 'QH', 'QD', 'QC', 'QS', 'KH', 'KD', 'KC', 'KS', 'AH', 'AD', 'AC', 'AS', 'BH', 'BD', 'BC'] images = [] for name in spinner: images.append(PhotoImage(file='cards/gfx/'+name+'.png') return images