Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Python Code Snippets #21
- 104-Scrolled text reader
- By Steve Shambles.
- stevepython.wordpress.com
- """
- from tkinter import Frame, INSERT, scrolledtext, Tk
- root = Tk()
- root.title('ViewText')
- main_frame = Frame(root)
- main_frame.grid(padx=10, pady=10)
- # Change bg to any colour you want for the background.
- # fg for ink colour of text.
- # Change width and height for different sizes, in characters.
- txt = scrolledtext.ScrolledText(main_frame, bg='gold', fg='black',
- width=70, height=30)
- txt.grid()
- # The text file to be read in and displayed.
- with open('test.txt', 'r') as f:
- text_contents=f.read()
- txt.insert(INSERT, text_contents)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement