Tkinter text widget

Simon Forman sajmikins at
Sun Oct 7 17:00:07 CEST 2007

On Oct 6, 11:18 pm, goldtech <goldt... at> wrote:
> I thought the "DISABLED" made it so I could not edit it. But it also
> makes it so I can not scroll down. If you make the window smaller than
> the content then try to put a cursor in there to use up/down arrow you
> can't.
> What I want is not to be able to change text content, but no other
> action is disabled. Is this complicated to do?
> Thanks.
> from Tkinter import *
> root = Tk()
> text = Text(root, font=("Courier"))
> text.pack()
> i='123456789abcdefghijklmnopqrstuvwxyz\n'
> for x in range(30):
>     text.insert(END, i)
> text.config(state=DISABLED)
> mainloop()

I just tried this script.  You can select text and if you drap the
selection outside the window then scrolling occurs, also Tk's default
behavior of scrolling with the middle button still works (i.e. click-
and-drag with the middle button to scroll.)

The arrow keys don't scroll the window, but that's because either A.
the Text widget won't take 'focus' while disabled -or- B. the arrow
keys et. al. work through the cursor which isn't there in disabled
mode.  I'm guessing and I'm not sure which is right, or if it's
something else entirely.

Try adding a scrollbar widget and tying it to the Text (there are
webpages out there that describe how to do this),  I think this widget
would still get focus (since it's NOT disabled) and therefore be able
to scroll the Text.  Or try explicitly binding the arrow keys to
scroll commands.


More information about the Python-list mailing list