Tkinter text widget

Discussion in 'Python' started by goldtech, Oct 7, 2007.

  1. goldtech

    goldtech Guest

    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()
     
    goldtech, Oct 7, 2007
    #1
    1. Advertising

  2. goldtech

    ezd Guest

    On Oct 6, 11:18 pm, goldtech <> 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
     
    ezd, Oct 7, 2007
    #2
    1. Advertising

  3. goldtech

    goldtech Guest


    > 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.
     
    goldtech, Oct 7, 2007
    #3
  4. goldtech

    Simon Forman Guest

    On Oct 6, 11:18 pm, goldtech <> 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
     
    Simon Forman, Oct 7, 2007
    #4
  5. goldtech

    goldtech Guest

    On Oct 7, 11:00 am, Simon Forman <> wrote:
    > On Oct 6, 11:18 pm, goldtech <> 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...
     
    goldtech, Oct 8, 2007
    #5
  6. goldtech

    goldtech Guest

    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()
     
    goldtech, Oct 8, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex9968
    Replies:
    0
    Views:
    583
    Alex9968
    Mar 19, 2008
  2. Alex9968
    Replies:
    0
    Views:
    1,526
    Alex9968
    Mar 19, 2008
  3. Frederic Rentsch
    Replies:
    0
    Views:
    251
    Frederic Rentsch
    Jul 8, 2012
  4. Terry Reedy
    Replies:
    15
    Views:
    640
    Frederic Rentsch
    Jul 16, 2012
  5. Frederic Rentsch
    Replies:
    0
    Views:
    434
    Frederic Rentsch
    Jul 9, 2012
Loading...

Share This Page