Saturday, July 27, 2013

BARE BONES TEXT EDITOR

I created a simple letter viewer for work. All it does is open the letter, but it can save changes too. I'm going to add it to my letter writing program at work.
from Tkinter import *
#A bare bones editor to view or make changes to a letter if needed.

def save_changes():
    f=open('theletter.txt','w')
    theletter=textwindow.get("1.0",END)
    f.write(theletter)
    f.close()
    print("Edits saved ")

def loadletter():
    f=open('theletter.txt','r')
   
    for line in f:
        textwindow.insert("30.0",line)#change the 30 to match file length
   
root=Tk()

textwindow=Text(root,background='white')
textwindow.pack()
btn=Button(root,text='Save changes',command=save_changes)
btn.pack()

loadletter()

root.mainloop()
 

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Biking helps me to cope with life.