Show a file in a text widget : Text « GUI Tk « Python






Show a file in a text widget

 


from Tkinter import *
import Pmw, sys
filename = "index.htm"
root = Tk()            
top = Frame(root); top.pack(side='top')
text = Pmw.ScrolledText(top,
       borderframe=5, 
       vscrollmode='dynamic', 
       hscrollmode='dynamic',
       labelpos='n', 
       label_text='file %s' % filename,
       text_width=40, 
       text_height=4,
       text_wrap='none',
       )
text.pack()

text.insert('end', open(filename,'r').read())
Button(top, text='Quit', command=root.destroy).pack(pady=15)
root.mainloop()

   
  








Related examples in the same category

1.Draw textDraw text
2.Draw text with fontDraw text with font
3.Scrolled TextScrolled Text
4.Change color for tagsChange color for tags
5.Change font for TextChange font for Text
6.Add double click action to a TextAdd double click action to a Text
7.Insert String to a TextInsert String to a Text
8.Text properties: expand and fillText properties: expand and fill
9.Text with ScrollBarText with ScrollBar
10.Search string in TextSearch string in Text