Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103834
| 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> (permalink) |
| 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 |
Show key headers only | View raw
Recently I was puzzled by a tkinter problem. The codes below (from a book) can display the picture correctly.
gifdir = "../gifs/"
from tkinter import *
win = Tk()
photo = PhotoImage(file=gifdir + "ora-pp.gif")
Button(win, image=photo).pack()
win.mainloop()
And the codes below (from another book) will also work.
class DrumMachine:
....
....
def create_play_bar(self):
....
....
photo = PhotoImage(file='images/signature.gif')
label = Label(playbar_frame, image=photo)
label.image = photo
label.grid(row=start_row, column=50, padx=1, sticky='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 = 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-picture-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 will 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?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
How to know if an object is still be referenced? jfong@ms4.hinet.net - 2016-03-01 18:35 -0800
Re: How to know if an object is still be referenced? Terry Reedy <tjreedy@udel.edu> - 2016-03-02 02:03 -0500
Re: How to know if an object is still be referenced? jfong@ms4.hinet.net - 2016-03-02 03:35 -0800
Re: How to know if an object is still be referenced? sohcahtoa82@gmail.com - 2016-03-02 15:38 -0800
Re: How to know if an object is still be referenced? jfong@ms4.hinet.net - 2016-03-02 18:36 -0800
csiph-web