By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

Tkinter image and scrollbar question

P: 31
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
  3.  
  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
  17.  
  18. def slideshow(Dir, Resw, Resh, Nslides):
  19.     root=Tk()
  20.     root.title("Slide Viewer")
  21.     root.minsize(width=(Resw+100), height=(Resh+100))
  22.  
  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)
  27.  
  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)
  42.  
  43.     scrollbar=Scrollbar()
  44.     scrollbar.config(command=canv.xview, orient='horizontal')
  45.     scrollbar.pack(side=TOP, fill=X)
  46.  
  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)
  56.  
  57.     label2=Label()
  58.     label2["text"]="Enter the slide range (Lower and Upper bounds inclusive)"
  59.     label2.pack(side=BOTTOM)
  60.  
  61.     root.mainloop()
  62.  
  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!
JP
Nov 24 '07 #1
Share this Question
Share on Google+
3 Replies


P: 31
shameless bump

It would be quite helpful to find out this answer.

JP
Nov 30 '07 #2

P: 75
[code]
#slidepic=outputdir+"\\breast2.JPG"
What kind of images are you looking at? hahah xD
Dec 3 '07 #3

P: 31
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.