Re: Tkinter Image Button Bug
In article <email@example.com>,
Erhan Ekici <firstname.lastname@example.org> wrote:
>There is a problem in my code.I think it is Tkinter bug....
>it works but doesn't display image. Instead of
>image, only a square with color=#dddddd comes on screen.
I think you are running into a common Tkinter pitfall (it is an
intentional design decision, but I do not recall the argument for it):
you need to explicitly maintain references to images; putting them in a
Tkinter widget is not sufficient.
In your code "icon" is garbage-collected when the function exits because
using it to set the icon of the label b does not increment its reference
I am almost certain it suffices to assign b._iconref = icon (_iconref
being an attribute that the Label b is not likely to already have).
I've appended your code suitably modified. I've not tested it.
>from Tkinter import *
> toolbar= Frame(master)
> pfile ="C:\\Python22\\samples\\ftp\\images\\help.gif"
> icon = PhotoImage(file=pfile)
> b=Label(toolbar, image=icon, width=10)
b._iconref = icon
> b.config(background="#dddddd", bd=1, relief=FLAT)
> b.pack(side=LEFT, padx=2, pady=2)
> #toolbar.config(background="#ffffff", bd=2, relief=GROOVE)
> toolbar.pack(side=TOP, expand=YES, fill=X)
|All times are GMT. The time now is 03:10 AM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.