Tkinter Text widget scrolling

Matthew Dixon Cowles matt at mondoinfo.com
Fri Mar 14 16:27:55 EST 2003


On 13 Mar 2003 06:08:43 -0800, student <student00 at angelfire.com>
wrote:

> Hi,

Hi!

> I'm fairly new to python, and just started working with Tkinter

> I want to know if theres a way to change the scroll range in the
> text widget.

> When text gets larger than the viewable size of the text widget, the
> scroll is automatically resized, however i want to override this so
> theres a little white space underneath insted of having the last
> liine at the bottom.

> Due to the nature of the application i'm writing, simply adding
> space at the bottom won't do, i need away to work with the scroll
> range....  any ideas?

You can do that but it will be at least a minor nuisance. You'll need
to use the place geometry manager and do the communication with the
scrollbar yourself. The essence of the scrolling is that you can give
the place geometry manager negative offsets. Here's a tiny example
that shows what I mean:

>>> from Tkinter import *
>>> r=Tk()
>>> t=Text(r)
>>> t.place(x=0,y=0,relheight=1,relwidth=1)
>>> t.insert(END,"Wibble")
>>> t.place(y=-5,relheight=1,height=5)
>>> t.place(y=-10,relheight=1,height=10)

The height option is added after the relheight option is taken
into account so you're stretching the Text widget while you're
allowing its top to move "above" the window.

Regards,
Matt




More information about the Python-list mailing list