Tough Tkinter Scrollregion vs Window Size Problem

S

syed_saqib_ali

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top