471,348 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Tkinter text widget

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

Oct 7 '07 #1
5 5111
ezd
On Oct 6, 11:18 pm, goldtech <goldt...@worldpost.comwrote:
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()
You can scroll, but you can't see the cursor. Use

for x in range(30):
text.insert(END, "%3d " % x + i)

to check.

ED

Oct 7 '07 #2
You can scroll, but you can't see the cursor. Use

for x in range(30):
text.insert(END, "%3d " % x + i)

to check.

ED
I tried it w/the line numbers. On my system I see 0-23.

But there is no way to scroll. Still the same result.

Oct 7 '07 #3
On Oct 6, 11:18 pm, goldtech <goldt...@worldpost.comwrote:
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.
~Simon

Oct 7 '07 #4
On Oct 7, 11:00 am, Simon Forman <sajmik...@gmail.comwrote:
On Oct 6, 11:18 pm, goldtech <goldt...@worldpost.comwrote:
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.)
Yes, if I depress the mouse's scroll wheel (the middle button) I can
drag the content up/down. Interesting...I didn't know that. But I
can't select, XP Python 2.1.

I'll try adding scroll bars. Thanks.

....snip...

Oct 8 '07 #5
After some Google searching I found "ScrolledText", this does what I
want :^)
from Tkinter import *
from ScrolledText import ScrolledText
root = Tk()
text = ScrolledText(root, font=("Courier"))
ScrolledText
text.pack()
i='123456789abcdefghijklmnopqrstuvwxyz\n'
for x in range(30):
text.insert(END, "%3d " % x + i)
text.config(state=DISABLED)
mainloop()

Oct 8 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Pekka Niiranen | last post: by
2 posts views Thread by Tonino | last post: by
7 posts views Thread by Harlin Seritt | last post: by
2 posts views Thread by Grooooops | last post: by
8 posts views Thread by Dustan | last post: by
reply views Thread by Stewart Midwinter | last post: by
1 post views Thread by vijayca | last post: by
3 posts views Thread by J-Burns | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.