ScrolledText
to create a text box that I insert text in each line.The problem
The problem was that when I inserted new text, the text box would not automatically scroll down to reveal the new text.
The solution
The solution turned out to be the
yview
method.In the example below, I added while loop of 100 numbers(lines) to demonstrate that noew the text box is now focussed to the bottom of the text.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###Tkinter Scrolling with Text### | |
'''Make text scroll to the bottom of the text box as new entries appear''' | |
from tkinter import * | |
from tkinter.scrolledtext import * | |
window = Tk() | |
window.wm_title("Scroll From Bottom") | |
TextBox = ScrolledText(window, height='10', width='45', wrap=WORD) | |
# | |
#Just adds 100 lines to the TextBox | |
count = 0 | |
while(count<100): | |
TextBox.insert(END, "The count is: " +str(count)+"\n") | |
#Pushes the scrollbar and focus of text to the end of the text input. | |
TextBox.yview(END) | |
count += 1 | |
TextBox.pack() | |
window = mainloop() | |
No comments:
Post a Comment