Tkinter text widget

G

goldtech

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

ezd

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
 
G

goldtech

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

Simon Forman

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
 
G

goldtech

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

goldtech

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top