2007年05月02日 星期三 16:03
ÎÒÏë°ÑÒ»¸öÎļþ¼ÐÀïµÄͼƬ£¬¶¼ÏÔʾ³öÀ´£¬Ô´´úÂëÈçÏ£º #!/usr/bin/env python import os,sys from Tkinter import * from glob import glob from ImageTk import PhotoImage imgdir = '/home/beibei/media/photo/' def show_photos(imgdir): win.title('show photos') photos = map(lambda x: (x,PhotoImage(file=x)),glob(imgdir+'*.jpg')) savephotos = [] for (name,item) in photos: Label(win,image=item).pack(side=LEFT) savephotos.append(item) return savephotos if __name__ == '__main__': win = Tk() photo = show_photos(imgdir) win.mainloop() µ«ÊÇÓÐÒ»µã²»Ã÷°×£ºsavephotos = [] savephotos.append(item) return savephotos ÕâÈý¾ä£¬ÔÚ´ËÓÐʲôÒâÒ壿·µ»ØµÄÊý¾ÝÓÖûÓÐÔÚÏÂÎÄÖ±½Óµ÷Ó㿵«ÊÇ£¬Èç¹ûɾȥ£¬ÓÖ²»ÄÜÕý³£ÏÔʾͼƬ£¿ÓеãÃÔ»ó£¬ËÄÜÖ¸µãһϣ¿¶àл£¿ -- ÈËÉú¾ÍÏñÒ»¸öÆ¿×Ó£¬¶øÉú»î¾ÍÊÇÆ¿×ÓÀïµÄË®¡£ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070502/90059985/attachment.html
2007年05月02日 星期三 16:25
On 5/2/07, xiaoyi tian <purpen.w在gmail.com> wrote: > 我想把一个文件夹里的图片,都显示出来,源代码如下: > > #!/usr/bin/env python > > import os,sys > from Tkinter import * > from glob import glob > from ImageTk import PhotoImage > > imgdir = '/home/beibei/media/photo/' > def show_photos(imgdir): > win.title('show photos') > photos = map(lambda x: > (x,PhotoImage(file=x)),glob(imgdir+'*.jpg')) > > savephotos = [] > for (name,item) in photos: > Label(win,image=item).pack(side=LEFT) > savephotos.append(item) > return savephotos > > > if __name__ == '__main__': > win = Tk() > photo = show_photos(imgdir) > win.mainloop() > > > 但是有一点不明白:savephotos = [] savephotos.append(item) return savephotos > 这三句,在此有什么意义?返回的数据又没有在下文直接调用?但是,如果删去,又不能正常显示图片?有点迷惑,谁能指点一下?多谢? 我想是因为作用域的原因,如果不保存,在执行完show_photos之后图片就会自动释放,所以图片无法显示。这样做是为了不让图片释放。 -- I like python! UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou
2007年05月02日 星期三 16:30
àÞ£¬ÕâÑù°¡£¬¶àл£¡ ÔÚ07-5-2£¬limodou <limodou在gmail.com> дµÀ£º > > On 5/2/07, xiaoyi tian <purpen.w在gmail.com> wrote: > > ÎÒÏë°ÑÒ»¸öÎļþ¼ÐÀïµÄͼƬ£¬¶¼ÏÔʾ³öÀ´£¬Ô´´úÂëÈçÏ£º > > > > #!/usr/bin/env python > > > > import os,sys > > from Tkinter import * > > from glob import glob > > from ImageTk import PhotoImage > > > > imgdir = '/home/beibei/media/photo/' > > def show_photos(imgdir): > > win.title('show photos') > > photos = map(lambda x: > > (x,PhotoImage(file=x)),glob(imgdir+'*.jpg')) > > > > savephotos = [] > > for (name,item) in photos: > > Label(win,image=item).pack(side=LEFT) > > savephotos.append(item) > > return savephotos > > > > > > if __name__ == '__main__': > > win = Tk() > > photo = show_photos(imgdir) > > win.mainloop() > > > > > > µ«ÊÇÓÐÒ»µã²»Ã÷°×£ºsavephotos = [] savephotos.append(item) return savephotos > > ÕâÈý¾ä£¬ÔÚ´ËÓÐʲôÒâÒ壿·µ»ØµÄÊý¾ÝÓÖûÓÐÔÚÏÂÎÄÖ±½Óµ÷Ó㿵«ÊÇ£¬Èç¹ûɾȥ£¬ÓÖ²»ÄÜÕý³£ÏÔʾͼƬ£¿ÓеãÃÔ»ó£¬ËÄÜÖ¸µãһϣ¿¶àл£¿ > > ÎÒÏëÊÇÒòΪ×÷ÓÃÓòµÄÔÒò£¬Èç¹û²»±£´æ£¬ÔÚÖ´ÐÐÍêshow_photosÖ®ºóͼƬ¾Í»á×Ô¶¯ÊÍ·Å£¬ËùÒÔͼƬÎÞ·¨ÏÔʾ¡£ÕâÑù×öÊÇΪÁ˲»ÈÃͼƬÊÍ·Å¡£ > > -- > I like python! > UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad > My Blog: http://www.donews.net/limodou > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- ÈËÉú¾ÍÏñÒ»¸öÆ¿×Ó£¬¶øÉú»î¾ÍÊÇÆ¿×ÓÀïµÄË®¡£ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070502/97be5b23/attachment.html
Zeuux © 2025
京ICP备05028076号