472,779 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 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
  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 4795
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

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

Similar topics

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...
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...
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...
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...
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?
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....
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...
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...
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()
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.