Am trying to Learn Tkinter. The following program works fine. It creates a textbox and a scrolllbar connected to the textbox. There is also a button, which when pressed inserts a line into the text box. Now what I want to do is to move the scrollbar such that when the text goes beyond the first screen, the scrollbar automatically scrolls down so that the user sees only the last line of the input. What I want to do is for the text box to behave like an extended stats window, so that the user is able to see the progress so far. Right now the user will continuously have to scroll down by using the scrollbar to the last line. I want this process to be automatic. Is there a command which I can use to do that?
Thanks!
from Tkinter import *
root = Tk()
def checkFn():
text.insert(END, ' --> The check button has been pressed ... \n')
# ............... Frame 1 .................................
frame1 = Frame(root)
frame1.pack(side=TOP, fill=X)
b = Button(frame1, text='Check', command=checkFn)
b.pack(side=LEFT, padx=5)
# .............. Text Frame .................................
frame10 = Frame(root)
frame10.pack(side=TOP, fill=X)
scrlBar = Scrollbar(frame10)
scrlBar.pack(side=RIGHT, fill=Y)
text = Text(frame10, yscrollcommand=scrlBar.set)
text.insert(INSERT, 'abcd\n')
text.pack(side=LEFT, fill=BOTH)
scrlBar.config(command=text.yview)
root.mainloop()
Am trying to Learn Tkinter. The following program works fine. It creates a textbox and a scrolllbar connected to the textbox. There is also a button, which when pressed inserts a line into the text box. Now what I want to do is to move the scrollbar such that when the text goes beyond the first screen, the scrollbar automatically scrolls down so that the user sees only the last line of the input. What I want to do is for the text box to behave like an extended stats window, so that the user is able to see the progress so far. Right now the user will continuously have to scroll down by using the scrollbar to the last line. I want this process to be automatic. Is there a command which I can use to do that?
Thanks!
from Tkinter import *
root = Tk()
def checkFn():
text.insert(END, ' --> The check button has been pressed ... \n')
# ............... Frame 1 .................................
frame1 = Frame(root)
frame1.pack(side=TOP, fill=X)
b = Button(frame1, text='Check', command=checkFn)
b.pack(side=LEFT, padx=5)
# .............. Text Frame .................................
frame10 = Frame(root)
frame10.pack(side=TOP, fill=X)
scrlBar = Scrollbar(frame10)
scrlBar.pack(side=RIGHT, fill=Y)
text = Text(frame10, yscrollcommand=scrlBar.set)
text.insert(INSERT, 'abcd\n')
text.pack(side=LEFT, fill=BOTH)
scrlBar.config(command=text.yview)
root.mainloop()
0 commentaires:
Enregistrer un commentaire