Tkinter Image Button Bug

Erhan Ekici erhan at uzem.itu.edu.tr
Wed Jul 2 10:24:55 EDT 2003


Hi,

There is a problem in my code.I think it is Tkinter bug.
Because First Code works properly and display the image on screen.
In Second Code(with function), it works but doesn't display image.Instead of 
image, only a square with color=#dddddd comes on screen.
Also , Third Code works properly and display image on screen...

What is Problem..I will use this code in function..(Second Code) 
(My System: WinXP Pro, Python2.2 )

First Code:
*************************************************************
from Tkinter import *

master=Tk()
toolbar= Frame(master)
pfile ="C:\\Python22\\samples\\ftp\\images\\help.gif"
icon = PhotoImage(file=pfile)
b=Button(toolbar, image=icon, width=16,command=master.quit)
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)


master.mainloop()   

*************************************************************

SECOND CODE
*************************************************************
from Tkinter import *

main=Tk()

def toolbar(master):
    toolbar= Frame(master)
    pfile ="C:\\Python22\\samples\\ftp\\images\\help.gif"
    icon = PhotoImage(file=pfile)
    b=Label(toolbar, image=icon, width=10)
    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)
       

toolbar(main)
main.mainloop()
*************************************************************


THIRD CODE
**********************************************
from Tkinter import *

main=Tk()

def toolbar(master):
    toolbar= Frame(master)
    pfile ="C:\\Python22\\samples\\ftp\\images\\help.gif"
    icon = PhotoImage(file=pfile)
    b=Label(toolbar, image=icon, width=10)
    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)
    master.mainloop()   

toolbar(main)
***************************************************

Thanks for answers :)

Erhan Ekici
ITU Center for Distance Learning
E-mail : erhan at uzem.itu.edu.tr








More information about the Python-list mailing list