text widget example?
jmdeschamps at gmail.com
jmdeschamps at gmail.com
Sun Nov 6 21:11:08 EST 2005
Well, in the 'give me a free example' type questions, I guess I'm a bit
blue tonight, so here goes: ( no personal pun intended, just look up
some recent post in this newsgroup...)
# Start the example Python code to show some text file in a text widget
from Tkinter import * # import Tkinter in __main__ namespace
root = Tk() # initialize Tkinter
myTextWidget= Text(root) # set up a text widget as a root (window)
child
myFile=file("myTextFile.txt") # get a file handle
myText= myFile.read() # read the file to variable
myFile.close() # close file handle
myTextWidget.insert(0.0,myText) # insert the file's text into the text
widget
myTextWidget.pack(expand=1, fill=BOTH) # show the widget
root.mainloop() #run the events mainloop
# End the example here
You need a text file *myTextFile.txt* in your current working directory
for this to work.
Read-up on the different objects and properties for detail.
Good luck!
BTW, now that this is posted, I guess one could say that it's an
example on the Internet
More information about the Python-list
mailing list