470,590 Members | 2,638 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,590 developers. It's quick & easy.

Tkinter image and scrollbar question

Hi everyone,

I am working on a module for my GUI that shows one image with an index value below and would use a scrollbar to control which of the images are displayed. The images are stored in a successive folder in the format Pic#, i,e. Pic1, Pic2 etc.

What I want to do is make a slider that is attached to a label which would output the slide number that is being looked at. I would use that number then to return the image of the slide to the TK window/canvas. I'm slightly succesfull using the scrollbar and loading images, however, I have yet to figure out how to do a simple scrollbar with a set amount of indices such as numbers 1-140 (which would be all of the pictures in the directory 1-n where n=140).

Here is some of my code, most importantly I would like to see a way of setting the slider to a preset beginning and maximum before I load the specific picture.
Expand|Select|Wrap|Line Numbers
  1. #  This module creates a slide show viewer in the Tk environment
  2. #  Its main purpose is to quickly decide the slide range to be used
  4. from Tkinter import *
  5. import Tkinter
  6. import Image            #  PIL
  7. import ImageTk          #  PIL
  8. import sys
  9. import getopt
  10. from tkMessageBox import *
  11. import tkFileDialog
  12. from time import *
  13. from os import *
  14. from math import *
  15. from array import *
  16. import ImageDraw
  18. def slideshow(Dir, Resw, Resh, Nslides):
  19.     root=Tk()
  20.     root.title("Slide Viewer")
  21.     root.minsize(width=(Resw+100), height=(Resh+100))
  23.     canv=Canvas(bg="yellow", relief=SUNKEN)
  24.     canv.config(width=Resw, height=Resh)
  25.     canv.config(scrollregion=(0,0,1000,500))
  26.     canv.pack(expand=YES, fill=BOTH)
  28.     for i in range(1,11):
  29.         slidepic=outputdir+"\\breast"+str(i)+".JPG"
  30.         print slidepic
  31.         im=Image.open(slidepic)
  32.         jpg1=ImageTk.PhotoImage(im)
  33.         canv.create_image(0,10,image=jpg1, anchor=NW)
  34.     #slidepic=outputdir+"\\breast2.JPG"
  35.     #im = Image.open(slidepic)
  36.     #jpg1=ImageTk.PhotoImage(im)
  37.     #canv.create_image(50,10,image=jpg1, anchor=NW)
  38.     #slidepic=outputdir+"\\breast100.JPG"
  39.     #im = Image.open(slidepic)
  40.     #jpg2=ImageTk.PhotoImage(im)
  41.     #canv.create_image(400,10,image=jpg2, anchor=NW)
  43.     scrollbar=Scrollbar()
  44.     scrollbar.config(command=canv.xview, orient='horizontal')
  45.     scrollbar.pack(side=TOP, fill=X)
  47.     bottomframe=Frame(root)
  48.     entry1=Entry(bottomframe)
  49.     entry1.pack(side=LEFT)
  50.     entry2=Entry(bottomframe)
  51.     label1=Label(bottomframe)
  52.     label1["text"]="-"
  53.     label1.pack(side=LEFT)
  54.     entry2.pack(side=RIGHT)
  55.     bottomframe.pack(side=BOTTOM)
  57.     label2=Label()
  58.     label2["text"]="Enter the slide range (Lower and Upper bounds inclusive)"
  59.     label2.pack(side=BOTTOM)
  61.     root.mainloop()
  63. #  Tests
  64. outputdir=r"C:\Unity Test\11 Nov 2007 210823\slides"
  65. slideshow(outputdir, 512, 512, 144)

Thank you very much for the help!
Nov 24 '07 #1
3 4466
shameless bump

It would be quite helpful to find out this answer.

Nov 30 '07 #2
What kind of images are you looking at? hahah xD
Dec 3 '07 #3
What kind of images are you looking at? hahah xD

Hah, the images are CTs for my masters work. Mind in the gutter I say!
Dec 19 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Thomas Buschhardt | last post: by
4 posts views Thread by Patrick L. Nolan | last post: by
1 post views Thread by syed_saqib_ali | last post: by
reply views Thread by syed_saqib_ali | last post: by
8 posts views Thread by Dustan | last post: by
1 post views Thread by C D Wood | last post: by
1 post views Thread by Hunter.lennon | last post: by
2 posts views Thread by goldtech | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.