468,234 Members | 1,679 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,234 developers. It's quick & easy.

Tough Tkinter Scrollregion vs Window Size Problem


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 original canvas-size, then the scrollregion adjusts
properly.
How can I make it such that the Scrollregion fills the entire space
avaialable to it. I tried all permutations of setting
expand=Tkinter.YES and fill=Tkinter.BOTH in the pack command??
-Saqib

----------------------------------------------------

import Tkinter

class testApp2:

def _setupCanvas(self):
self._canvasFrame = Tkinter.Frame(self._overallFrame, bd=1,
relief=Tkinter.SUNKEN)
self._canvasFrame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)

self._canvas = Tkinter.Canvas(self._canvasFrame,
background="white", width=self._canvasWidth,
height=self._canvasHeight,)
# Scroll Bars
vScrollbar = Tkinter.Scrollbar(self._canvasFrame)
hScrollbar = Tkinter.Scrollbar(self._canvasFrame)

# Scroll Bars
vScrollbar = Tkinter.Scrollbar(self._canvasFrame)
vScrollbar.pack(side=Tkinter.LEFT, expand=Tkinter.NO,
fill=Tkinter.NONE)

hScrollbar = Tkinter.Scrollbar(self._canvasFrame)
hScrollbar.pack(side=Tkinter.TOP, expand=Tkinter.NO,
fill=Tkinter.NONE)

# Configure
self._parent.rowconfigure(0, weight=1)
self._parent.columnconfigure(0, weight=1)
# self._scrollX0 = self._scrollY0 = 0
# self._scrollX1 = self._canvasWidth
# self._scrollY1 = self._canvasHeight
print "self._canvasWidth = %s" % self._canvasWidth
print "self._canvasHeight = %s" % self._canvasHeight
# print "self._scrollX1 = %s" % self._scrollX1
# print "self._scrollY1 = %s" % self._scrollY1
self._canvas.config(
width=self._canvasWidth,
height=self._canvasHeight,
scrollregion=(0,0, self._canvasWidth, self._canvasHeight),
yscrollcommand=vScrollbar.set,
xscrollcommand=hScrollbar.set,
)

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

self._canvasFrame.pack()
self._canvas.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)
vScrollbar.pack(side=Tkinter.RIGHT, expand=Tkinter.YES,
fill=Tkinter.Y)
hScrollbar.pack(side=Tkinter.BOTTOM, expand=Tkinter.YES,
fill=Tkinter.X)


def __init__(self, parent):
self._parent = parent

self._overallFrame = Tkinter.Frame(self._parent, bd=1,
relief=Tkinter.SUNKEN)
self._overallFrame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)
self._canvasWidth = 300
self._canvasHeight = 250
self._setupCanvas()
self._setCallBacks()



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

def _b1PressEvt(self, event):
print self._canvas.config('scrollregion')
print self._canvas.config('width')
print self._canvas.config('height')
print "=" * 50
print "\n"

root = Tkinter.Tk()
app = testApp2(root)
root.mainloop()

Aug 4 '05 #1
0 3177

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Fuzzyman | last post: by
1 post views Thread by Pekka Niiranen | last post: by
1 post views Thread by syed_saqib_ali | last post: by
reply views Thread by Stewart Midwinter | last post: by
1 post views Thread by Bob Greschke | last post: by
4 posts views Thread by D | last post: by
reply views Thread by WaterWalk | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.