[Image-SIG] Tkinter Scroll Bar Widget

K Schutte schutte at fel.tno.nl
Thu Nov 27 11:20:46 EST 2003


Siva,

Without sending you our complete application (which is proprietary),
see below the excerpt which seems to handle the scrollbars.

I know it did take quite some effort to get it working. Sending back
any improvements is appreciated!

Klamer

#
# The Python Imaging Library
# $Id: viewer.py,v 1.6 2003/10/28 10:51:45 kscp1 Exp $
#

from Tkinter import *
import Image, ImageTk, jfloatimage, jfloatimagec #, Pmw
import time, Queue
import threading, sys, os

#
# an image viewer

class UI(Canvas):

    def __init__(self, master, im, scroll = None):

        if im.mode == "1":
            # bitmap image
            self.image = ImageTk.BitmapImage(im, foreground="white")
            Label.__init__(self, master, image=self.image, bg="black", bd=0)

        else:
            # photo image
            #scx.grid(row=1,column=0,sticky=E+W)
            (w,h)=im.size
            Canvas.__init__(self,master, height=h,width=w,borderwidth=0)
            if (w > 512) or (h > 512) or (scroll != None):
                self.scroll = 1
                scy=Scrollbar(master)
                scy.pack(side=RIGHT,fill=Y)
                scx=Scrollbar(master,orient=HORIZONTAL)
                scx.pack(side=BOTTOM,fill=X)
                if (scroll != None):
                    self.config(xscrollcommand=scx.set,
                                yscrollcommand=scy.set, 
                                scrollregion=(0,0,w,h), height=512,width=512)
                else:
                    self.config(xscrollcommand=scx.set,
                                yscrollcommand=scy.set, 
                                scrollregion=(0,0,w,h))
                scx.config(command=self.xview)
                scy.config(command=self.yview)
            #self.grid(row=0,column=0,sticky=N+S+E+W)
            self.image = ImageTk.PhotoImage(im)
            self.canvasImage=self.create_image(0,0,image=self.image,anchor=NW)


Siva Chandra wrote:
> 
> Hello,
> 
> I have been using Tkinter for some time but now I am
> having to use a scroll bar for my image processing
> project. Can I get complete info on using the scroll
> bar widget. I am unable to control the lenght of the
> scroll and the tutorial isn't complete on this.
> Currently I am simulating a scroll bar using the scale
> widgets which is very-very slow.
> 
> thanx
> 
> =====
> Siva Chandra
> B-Tech, Electrical Engineering,
> IIT Madras.
> Currently pursuing MS by research at IIIT, Hyderabad
> visit www.geocities.com/sivachandra_br
> 
> __________________________________
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now
> http://companion.yahoo.com/
> 
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig

-- 
Klamer Schutte, E-mail: Schutte at fel.tno.nl
Intelligent Cameras, TNO Physics and Electronics Laboratory
Tel: +31-70-3740469 -- Fax: +31-70-3740654 -- Mobile: +31-6-51316671

-- 
------------------------------------------------------------------------------
The disclaimer that applies to e-mail from
TNO Physics and Electronics Laboratory
can be found on: http://www.tno.nl/disclaimer/email.html
------------------------------------------------------------------------------



More information about the Image-SIG mailing list