Tkinter Text widget scrolling

Chad Netzer cnetzer at mail.arc.nasa.gov
Fri Mar 14 17:08:23 EST 2003


On Fri, 2003-03-14 at 11:46, student wrote:

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

You could try using tags.  Tag the characters on the last line, and then
using tag_configure(), change the spacing3 attribute.

Here is my quick hack that almost works.  The problem seems to be that
the definition of 'end' changes depending on whether there is a single
newline at the end or not.  But it may be a start.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import Tkinter

if __name__ == '__main__':
    root = Tkinter.Tk()
    t = Tkinter.Text(root)
    t.pack()

    # Initialize with text
    t.insert( 'end', "abc\n" * 50)
    t.yview_moveto(1.0)

    # Setup tag of last line and increase spacing underneath
    t.tag_add('mylast', 'end - 1 lines', 'end - 0 lines')
    t.tag_configure('mylast', spacing3="30")

    root.mainloop()


-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
(any opinion expressed is my own and not NASA's or my employer's)







More information about the Python-list mailing list