473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
  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
3 4898
shameless bump

It would be quite helpful to find out this answer.

JP
Nov 30 '07 #2
dazzler
75
[code]
#slidepic=outputdir+"\\breast2.JPG"
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

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

Similar topics

1
by: Thomas Buschhardt | last post by:
Hallo, I have a problem with Tkinter and the module socket. In a console-window everything works fine, but in a Tkinter-window I can no more use the widgets. I found some other mails with this...
4
by: Patrick L. Nolan | last post by:
Our Tkinter application has a big ScrolledText widget which is a log of everything that happens. In order to prevent people from making changes, we have it in DISABLED mode except when the...
1
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
0
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
8
by: Dustan | last post by:
I'm trying to get a scrollbar bound with a Frame, and I keep on getting a scrollbar, but it doesn't actually scroll. Some help, please?
1
by: C D Wood | last post by:
To whom this may concern, Below is the source code, which demonstrates a problem I am having making a GUI for my python project work. 'table.txt' is a file that is read from the same folder....
2
by: jim-on-linux | last post by:
py help, The file below will run as a stand alone file. It works fine as it is. But, when I call it from another module it locks my computer, The off switch is the only salvation. This...
1
by: Hunter.lennon | last post by:
I want to create a custom scrollbar using particular images, which will then be placed on a canvas to control another window on the canvas. Right now I am inheriting from scrollbar, but I do the...
2
by: goldtech | last post by:
Hi, I'm stumped on how to have a scrollbar with a long list of checkboxes. Given code like: from Tkinter import * root = Tk() states = for i in range(150): var = IntVar()
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.