Advertisement
steve-shambles-2109

104-Scrolled text reader

Dec 5th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. """
  2. Python Code Snippets #21
  3. 104-Scrolled text reader
  4. By Steve Shambles.
  5. stevepython.wordpress.com
  6. """
  7. from tkinter import Frame, INSERT, scrolledtext, Tk
  8.  
  9. root = Tk()
  10. root.title('ViewText')
  11.  
  12. main_frame = Frame(root)
  13. main_frame.grid(padx=10, pady=10)
  14.  
  15. # Change bg to any colour you want for the background.
  16. # fg for ink colour of text.
  17. # Change width and height for different sizes, in characters.
  18.  
  19. txt = scrolledtext.ScrolledText(main_frame, bg='gold', fg='black',
  20.                                 width=70, height=30)
  21. txt.grid()
  22.  
  23. # The text file to be read in and displayed.
  24. with open('test.txt', 'r') as f:
  25.     text_contents=f.read()
  26.  
  27. txt.insert(INSERT, text_contents)
  28.  
  29. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement