Re: help please: tkinter grid layout is very slow

2014-11-13 Thread Terry Reedy

On 11/13/2014 3:45 PM, Rich Cook wrote:

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 slw? 
 :-)  Thanks

root = Tkinter.Tk()
root.geometry(1000x280+300+300)
label = Tkinter.Button(root, compound=Tkinter.TOP)
label.pack()

numimages = len(image_list)
numcols = 6
numrows = numimages/numcols


That should be 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(Image.open(image_list[imagenum]) )


ImageTk? or Tkinter?


 b.grid(row=row, column = col)

frame.pack()

root.mainloop()




--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: help please: tkinter grid layout is very slow

2014-11-13 Thread Chris Angelico
On Fri, Nov 14, 2014 at 7:45 AM, Rich Cook wealthyc...@gmail.com wrote:
 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(Image.open(image_list[imagenum]) )

You're asking someone somewhere to load 256 images into memory and
display them. What's the resolution of these images? Do they need to
be scaled/cropped? That can be fairly expensive. How long does it
actually take to (a) load all those images, and (b) pack the frame?
Try, for instance, commenting out the b.grid() call, to force them all
to be loaded but not packed.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list