X-Received: by 10.140.159.7 with SMTP id f7mr141562qhf.3.1456886110885; Tue, 01 Mar 2016 18:35:10 -0800 (PST) X-Received: by 10.50.29.108 with SMTP id j12mr72257igh.1.1456886110425; Tue, 01 Mar 2016 18:35:10 -0800 (PST) Path: csiph.com!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!y89no5046336qge.0!news-out.google.com!k1ni6017igd.0!nntp.google.com!ok5no5624403igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Tue, 1 Mar 2016 18:35:10 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=36.238.103.179; posting-account=G2sM6AoAAADOlDdo9rWD6sFkj3T5ULsz NNTP-Posting-Host: 36.238.103.179 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <8e9f1a84-cced-435e-a379-e1e2ac03f483@googlegroups.com> Subject: How to know if an object is still be referenced? From: jfong@ms4.hinet.net Injection-Date: Wed, 02 Mar 2016 02:35:10 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 2625 X-Received-Body-CRC: 1454408937 Xref: csiph.com comp.lang.python:103834 Recently I was puzzled by a tkinter problem. The codes below (from a book) = can display the picture correctly. gifdir =3D "../gifs/" from tkinter import * win =3D Tk() photo =3D PhotoImage(file=3Dgifdir + "ora-pp.gif") Button(win, image=3Dphoto).pack() win.mainloop() And the codes below (from another book) will also work. class DrumMachine: .... .... def create_play_bar(self): .... .... photo =3D PhotoImage(file=3D'images/signature.gif') label =3D Label(playbar_frame, image=3Dphoto) label.image =3D photo label.grid(row=3Dstart_row, column=3D50, padx=3D1, sticky=3D'w'= ) .... .... In the second example, I noticed that the "photo" was referenced two times = and I think it might be a redundancy so I remove the line "label.image =3D = photo". But it fails then. How can it be? one works and the other not. I search for answers on the web and here are some links talking about it: http://stackoverflow.com/questions/20812579/why-it-shows-blank-instead-of-p= icture-in-my-tkinter-program http://effbot.org/tkinterbook/photoimage.htm They all said that you have to keep a reference to the "photo" or else it w= ill be garbage collected. Now, as I had learn Python so far, I know that a = keyword argument passed in an object instantiation will bind this object to= its attribute name, i.e. create a reference to this object. (and it should= or the whole language will be in disaster) Can anyone help me out?