Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108925
| From | Peter Pearson <pkpearson@nowhere.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Image loading problem |
| Date | 2016-05-21 17:10 +0000 |
| Message-ID | <dqbj3bF77iU1@mid.individual.net> (permalink) |
| References | <743e5fbe-3a6c-49ea-ac5e-9bc055f652b5@googlegroups.com> |
On Sat, 21 May 2016 08:22:41 -0700 (PDT), sweating_ant@yahoo.com wrote:
>
> I am working on an image project, and I can display my image in
> main(). I mean, I can load my image in my main(). Needless, it is
> awkward. I am trying to load my image with a function, but got an
> empty image window popped up, no image content loaded. Please take a
> look at code:
>
> rom Tkinter import *
>
> def load_img(win):
> img = PhotoImage(file="xxx.gif")
> Label(win, image=img).pack()
>
> win = Tk()
> load_img(win)
> win.mainloop()
>
This seems to work:
-----------
from Tkinter import Tk, PhotoImage, Label
def load_img(win):
img = PhotoImage(file="/home/peter/dow.gif")
Label(win, image=img).pack()
return img
win = Tk()
img = load_img(win)
win.mainloop()
-----------
I guess the problem was that the "img" created in load_img went
out of scope and was deleted when load_img returned. I just tried
the "return img" as an experiment to keep it from going out of scope;
from a software-engineering standpoint this might be a gross kluge.
Baffling? Personally, I never got past feeling generally bewildered in
Tkinter-land, and now I use matplotlib for all my graphical needs. I
had great hopes for PyGUI at one point, but I hear very little about it
now.
--
To email me, substitute nowhere->runbox, invalid->com.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Image loading problem "sweating_ant@yahoo.com" <huey.y.jiang@gmail.com> - 2016-05-21 08:22 -0700
Re: Image loading problem Peter Otten <__peter__@web.de> - 2016-05-21 18:54 +0200
Re: Image loading problem Peter Pearson <pkpearson@nowhere.invalid> - 2016-05-21 17:10 +0000
Re: Image loading problem Gary Herron <gherron@digipen.edu> - 2016-05-21 10:16 -0700
Re: Image loading problem Terry Reedy <tjreedy@udel.edu> - 2016-05-21 15:23 -0400
Re: Image loading problem Random832 <random832@fastmail.com> - 2016-05-21 15:55 -0400
Re: Image loading problem huey.y.jiang@gmail.com - 2016-05-21 21:01 -0700
Re: Image loading problem Peter Otten <__peter__@web.de> - 2016-05-22 11:03 +0200
Re: Image loading problem Michael Torrie <torriem@gmail.com> - 2016-05-22 13:37 -0600
Re: Image loading problem Random832 <random832@fastmail.com> - 2016-05-22 16:19 -0400
Re: Image loading problem Christian Gollwitzer <auriocus@gmx.de> - 2016-05-22 22:57 +0200
csiph-web