Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to maintain scroll-region view while changing canvas size?

Thread Tools

How to maintain scroll-region view while changing canvas size?
Posts: n/a

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!!

I want to know how to expand the size of a canvas without changing the
area/size of what is currently shown by the scroll bars. I would like
to find code that expands the width of the canvas and simply adjusts
the H-Scrollbar without changing what is shown on in the area of the
canvas being displayed.

I have tried seemingly every combination of messing with the
canvas.config and scrollregion parameters to no avail. Can someone out
there show me how its done??


import Tkinter

def _b1PressEvt(event):
print "B1"

tkRoot = Tkinter.Tk()
_canvas = Tkinter.Canvas(tkRoot, background="white", width=200,

# Scroll Bars
vScrollbar = Tkinter.Scrollbar(tkRoot)
vScrollbar.pack(side=Tkinter.RIGHT, expand=True, fill=Tkinter.Y)

hScrollbar = Tkinter.Scrollbar(tkRoot)
hScrollbar.pack(side=Tkinter.BOTTOM, expand=True, fill=Tkinter.X)


vScrollbar.config(orient=Tkinter.VERTICAL, command=_canvas.yview)
hScrollbar.config(orient=Tkinter.HORIZONTAL, command=_canvas.xview)

vScrollbar.pack(side=Tkinter.RIGHT, expand=True, fill=Tkinter.Y)
hScrollbar.pack(side=Tkinter.BOTTOM, expand=True, fill=Tkinter.X)

# Function Bindings
_canvas.bind("<Button-1>", _b1PressEvt)


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
how to couper contenier of a canvas in an outer canvas??? Python 10 03-15-2013 08:46 PM
Canvas with scrollbars - how to get correct canvas coordinate when the scroll bars have moved? PhilC Python 2 10-25-2004 11:57 AM
Canvas scrolling - scrollBar become "disabled" on change in canvas Askari Python 2 08-30-2004 02:56 PM
How to make a week view and day view calendar just like month view calendar in .NET ? Parthiv Joshi ASP .Net Web Controls 1 07-06-2004 03:15 PM