Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter text widget

Reply
Thread Tools

Tkinter text widget

 
 
goldtech
Guest
Posts: n/a
 
      10-07-2007
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()

 
Reply With Quote
 
 
 
 
ezd
Guest
Posts: n/a
 
      10-07-2007
On Oct 6, 11:18 pm, goldtech <(E-Mail Removed)> 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()


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

 
Reply With Quote
 
 
 
 
goldtech
Guest
Posts: n/a
 
      10-07-2007

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

 
Reply With Quote
 
Simon Forman
Guest
Posts: n/a
 
      10-07-2007
On Oct 6, 11:18 pm, goldtech <(E-Mail Removed)> 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.


~Simon

 
Reply With Quote
 
goldtech
Guest
Posts: n/a
 
      10-08-2007
On Oct 7, 11:00 am, Simon Forman <(E-Mail Removed)> wrote:
> On Oct 6, 11:18 pm, goldtech <(E-Mail Removed)> 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.)


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

 
Reply With Quote
 
goldtech
Guest
Posts: n/a
 
      10-08-2007
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()

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Tkinter.event.widget: handler gets name instead of widget. Terry Reedy Python 15 07-16-2012 10:32 AM
Re: Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch Python 0 07-09-2012 08:39 PM
Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch Python 0 07-08-2012 09:19 PM
Re: Tkinter.Text widget - how to get text cursor position? Alex9968 Python 0 03-19-2008 07:07 PM
Tkinter.Text widget - how to get text cursor position? Alex9968 Python 0 03-19-2008 05:37 PM



Advertisments