PhotoImage: iterating over a list of images
Ian Oeschger
oeschger at netscape.com
Sat Oct 5 19:49:53 EDT 2002
Why does the example below display only img4.gif and not any of
the others. All of them are sitting in the same directory. Is there
something wrong about the way that I iterate over the list??
If I give a different variable to each icon name and create
PhotoImages and Buttons four different times, it seems to work.
Thanks for any advice.
.ian
#! /usr/bin/env python
from Tkinter import *
import Pmw
icon_list = ['img1.gif', 'img2.gif', 'img3.gif']
def makeBtn(icon):
Button(root, width=24, height=24, image=PhotoImage(file=icon), command=sys.exit).pack(side=RIGHT, padx=5, pady=5)
#################################################
root = Tk()
root.title('test')
icon = PhotoImage(file='img4.gif')
main_btn = Button(root, width=24, height=24, image=icon).pack(side=RIGHT, padx=5, pady=5)
for icon_name in icon_list:
makeBtn(icon_name)
##################################################
root.mainloop()
--
Ian Oeschger
Netscape Communications
More information about the Python-list
mailing list