Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80703 > unrolled thread
| Started by | Rich Cook <wealthychef@gmail.com> |
|---|---|
| First post | 2014-11-13 12:45 -0800 |
| Last post | 2014-11-14 10:39 +1100 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
help please: tkinter grid layout is very slow Rich Cook <wealthychef@gmail.com> - 2014-11-13 12:45 -0800
Re: help please: tkinter grid layout is very slow Terry Reedy <tjreedy@udel.edu> - 2014-11-13 17:14 -0500
Re: help please: tkinter grid layout is very slow Chris Angelico <rosuav@gmail.com> - 2014-11-14 10:39 +1100
| From | Rich Cook <wealthychef@gmail.com> |
|---|---|
| Date | 2014-11-13 12:45 -0800 |
| Subject | help please: tkinter grid layout is very slow |
| Message-ID | <91e0adb0-e4ef-4847-881a-7325e9a781d3@googlegroups.com> |
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()
root.geometry("1000x280+300+300")
label = Tkinter.Button(root, compound=Tkinter.TOP)
label.pack()
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(Image.open(image_list[imagenum]) )
b.grid(row=row, column = col)
frame.pack()
root.mainloop()
[toc] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2014-11-13 17:14 -0500 |
| Message-ID | <mailman.15790.1415916887.18130.python-list@python.org> |
| In reply to | #80703 |
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 sloooow? :-) 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
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-11-14 10:39 +1100 |
| Subject | Re: help please: tkinter grid layout is very slow |
| Message-ID | <mailman.15797.1415921951.18130.python-list@python.org> |
| In reply to | #80703 |
On Fri, Nov 14, 2014 at 7:45 AM, Rich Cook <wealthychef@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web