"""Text with scroll bars.""" from Tkinter import * class App: def __init__(self, parent): self.parent = parent self.create_widgets() def create_widgets(self): self.vbar = Scrollbar( self.parent, orient=VERTICAL) self.vbar.pack(side=RIGHT, fill=BOTH) self.hbar = Scrollbar( self.parent, orient=HORIZONTAL) self.hbar.pack(side=BOTTOM, fill=BOTH) self.text = Text(self.parent, width=40, height=10, wrap=NONE, selectbackground='yellow') self.text.pack(expand=1, fill=BOTH) self.text.config( yscrollcommand= (self.vbar, 'set')) self.vbar.config( command= (self.text, 'yview')) self.text.config( xscrollcommand= (self.hbar, 'set')) self.hbar.config( command= (self.text, 'xview')) self.text.insert( END, SAMPLE_DATA) SAMPLE_DATA = """ This is some example text, intended to fill the text widget up with some stuff to show the scroll bars. Note how the horizontal scroll bar reflects the maximum length of the currently visible lines (this is actually done by the text widget!). I might as well explain that there's a little problem with this version: the vertical scrollbar extends into the bottom right corner. If you have a problem with that, I believe that the only solution is to create a frame around one of the scroll bars (e.g. the vertical one) and to add a little empty box (a Frame widget will do nicely) to the end of that frame. The code is ugly and left to the reader as an exercise. Hint: you can ask for the width of any widet using the winfo_width() method. """ # Boilerplate from here on... if __name__ == '__main__': root = Tk() app = App(root) root.mainloop()