can any body help me to add icons to the toolbar, i know that we have to use PhotoImage class to add but i'm not able to see the image in the toolbar. here is the code which i wrote,

the following code is not an error, but im not getting the icon displayed.
please help me out.

from Tkinter import *


root=Tk()
def callback():
   print "tool bar button."
tool=Frame(root)

p=PhotoImage("calculator")  #its icon which is same directory where the my .py exists

b=Button(tool,text="New", width=15, height=15,image=p, command=callback)
b.pack(side=LEFT,padx=2,pady=2)
bb=Button(tool, width=6,text="Open", command=callback)
bb.pack(side=LEFT,padx=2,pady=2)

tool.pack(side=TOP, fill=X)

mainloop()

The PhotoImage class can only read GIF and PGM/PPM images from files. If you had an image file called calculator.gif in your working directory, you would use ...

p=PhotoImage(file="calculator.gif")

Also add something like compound=TOP to your button() to let tk know where your image is in relation to your text.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.