473,657 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter image and scrollbar question

31 New Member
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 4957
Nebulism
31 New Member
shameless bump

It would be quite helpful to find out this answer.

JP
Nov 30 '07 #2
dazzler
75 New Member
[code]
#slidepic=outpu tdir+"\\breast2 .JPG"
What kind of images are you looking at? hahah xD
Dec 3 '07 #3
Nebulism
31 New Member
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
2240
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 problem, but no solution (I understand really :-) Here is my code: ----------------------------------------------- import win32ui, dde, string, time, os, sys, shutil
4
5289
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 program wants to write a new entry. This works OK, except that sometimes we want to copy out of piece of the contents and paste it in another window. When it's DISABLED, it appears that we can't even select a portion of the text. Is this an...
1
2966
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 scroll-bars work as advertised. That's great. However, if you click the Left Mouse button, it calls code which expands the width of the canvas by 100 pixels. The area being viewed expands correspondingly..... BUT I DON'T WANT IT TO!!
0
3578
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 accordingly. However, what I really want to happen is that the area of the canvas that the scrollbars show (the Scrollregion) should expand as the window grows. It doesn't currently do this. although, if the window shrinks smaller than the...
8
11963
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
2656
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. My code writes to a text file 'table.txt', and 'table.txt' is displayed in
2
2322
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 module when run as a stand alone, it will
1
2951
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 movement with custom functions. When I create it and put in into the canvas with "canvas.create_window" a standard scrollbar shows in the correct spot and my custom one is outside of the canvas. All I have right now is something that moves...
2
9314
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
8382
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.