How to get ScrollRegion to adjust w/ window-size?

jepler at unpythonic.net jepler at unpythonic.net
Sat Aug 6 07:59:52 EDT 2005


The ScrollRegion of the canvas gives the area that should be "available"
for scrolling.  If this is larger than the visible area of the canvas,
then associated scrollbars will allow scrolling.  If this is smaller
than the visible area of the canvas, then the scrollbar will fill with
the "thumb" and no scrolling is possible.

Here is an application that creates a 5000x5000 canvas and allows
scrolling.  The scrollbars react appropriately when the window is
resized.


from Tkinter import *

t = Tk()

c = Canvas(t)
hsb = Scrollbar(t, orient="h", command=c.xview)
vsb = Scrollbar(t, orient="v", command=c.yview)
c.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set)

c.grid(row=0, column=0, sticky="nsew")
hsb.grid(row=1, column=0, stick="ew")
vsb.grid(row=0, column=1, sticky="ns")

t.grid_rowconfigure(0, weight=1)
t.grid_columnconfigure(0, weight=1)

c.configure(scrollregion = (0, 0, 5000, 5000))

for x in range(100, 5000, 100):
    for y in range(100, 5000, 100):
        c.create_text((x,y), anchor=CENTER, text="%d,%d" % (x,y))

t.mainloop()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050806/86c72299/attachment.sig>


More information about the Python-list mailing list