help please: tkinter grid layout is very slow

Rich Cook wealthychef at
Thu Nov 13 21:45:25 CET 2014

Hi, I'm trying to toss together an image browser in tkinter, and it is so slow it is unworkable.  Here is my code.  Can someone point out why it's so sloooow?  :-)  Thanks

root = Tkinter.Tk()
label = Tkinter.Button(root, compound=Tkinter.TOP)

numimages = len(image_list)
numcols = 6
numrows = numimages/numcols
if numrows * numcols != numimages:
    numrows += 1

frame = Tkinter.Frame(root)
for col in range(numcols):
    frame.columnconfigure(col, pad=2)

for row in range(numrows):
    frame.rowconfigure(row, pad=2)

print "There are", numimages, "images"  # 256 in fact... 
for imagenum, (row, col) in enumerate([(row,col) for row in range(numrows) for col in range(numcols)]):
    b = Tkinter.Label(frame, compound = Tkinter.TOP)
    b['text'] = os.path.basename(image_list[imagenum])
    b['image'] = ImageTk.PhotoImage([imagenum]) )
    b.grid(row=row, column = col)


More information about the Python-list mailing list