Python Forum
[Tkinter] scrolling text in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] scrolling text in tkinter
#2
I tossed this together to give you an example of one way it can be done.  Basically, you find out the current index, and repeatedly increment that until the index points somewhere that isn't currently visible, and then move the widget to display that index.
from tkinter import scrolledtext as st
from tkinter import constants as const

def scroll_textbox(elem):
    # get the current index
    current = float(elem.index(const.CURRENT))
    new = current
    # keep incrementing the index until it's not visible
    while elem.bbox(new):
        new += 1
    # make sure the new index is visible
    elem.see(new)
    # move the index again in 250ms
    elem.after(250, lambda: scroll_textbox(elem))

if __name__ == "__main__":
    # a little setup to demonstrate...
    stext = st.ScrolledText(bg='white', height=10)
    # kick off our callback
    stext.after(1000, lambda: scroll_textbox(stext))
    # shove a large amount of text in there
    stext.insert(const.END, ''' here's a very large block of text.
    
    it just keeps going...
    ''' + ('...and going...\n\n'*100))
    stext.pack(fill=const.BOTH, side=const.LEFT, expand=True)
    stext.focus_set()
    stext.mainloop()
Reply


Messages In This Thread
scrolling text in tkinter - by Barrowman - Oct-18-2016, 06:24 PM
RE: scrolling text in tkinter - by nilamo - Oct-18-2016, 07:41 PM
RE: scrolling text in tkinter - by metulburr - Oct-18-2016, 08:09 PM
RE: scrolling text in tkinter - by Barrowman - Oct-18-2016, 08:45 PM
RE: scrolling text in tkinter - by nilamo - Oct-18-2016, 09:04 PM
RE: scrolling text in tkinter - by Barrowman - Oct-18-2016, 09:55 PM
RE: scrolling text in tkinter - by metulburr - Oct-18-2016, 08:51 PM
RE: scrolling text in tkinter - by Barrowman - Oct-18-2016, 09:02 PM
RE: scrolling text in tkinter - by nilamo - Oct-18-2016, 10:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Updating tkinter text BliepMonster 5 6,448 Nov-28-2022, 01:42 AM
Last Post: deanhystad
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 5,264 Jun-26-2022, 06:26 PM
Last Post: menator01
  tkinter change the text of the checkbox zazas321 1 3,946 Sep-17-2021, 06:19 AM
Last Post: zazas321
  tkinter text widget word wrap position chrisdb 6 7,731 Mar-18-2021, 03:55 PM
Last Post: chrisdb
  [Tkinter] tkinter.Menu – How to make text-variable? Sir 3 5,743 Mar-10-2021, 04:21 PM
Last Post: Sir
  tkinter touchscreen scrolling - button press makes unwanted scrolling nanok66 1 4,091 Dec-28-2020, 10:00 PM
Last Post: nanok66
Photo Tkinter TEXT background image _ShevaKadu 5 7,939 Nov-02-2020, 10:34 AM
Last Post: joe_momma
  tkinter | Button color text on Click Maryan 2 3,460 Oct-09-2020, 08:56 PM
Last Post: Maryan
  [Tkinter] Text Upload LearningLittlebyLittle 0 2,086 Sep-04-2020, 07:55 PM
Last Post: LearningLittlebyLittle
  [Tkinter] Indentation for Tkinter-made Text Editor ShakeyPakey 4 5,254 Jun-08-2020, 03:13 PM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020