Saturday, November 16, 2013

Added Buttons and new functions to my Text Editor

from Tkinter import *
def cleargui():
    textwindow.delete("1.0",END)

def createfile(): #Creates a text file if none exitst.
    f=open('propertydescripts.txt','a')
   
   
def save_changes():
    f=open('propertydescripts.txt','a')
    theletter=textwindow.get("1.0",END)
    f.write('-----------------------------------------------------\n')
    f.write(theletter)
    f.close()
    cleargui()
    print("Edits saved ")

def loadletter():
    f=open('propertydescripts.txt','r')
  
    for line in f:
        textwindow.insert("300.0",line)#change the 300 to match file length

def showtext():
    f=open('propertydescripts.txt','a')
   
createfile()  
root=Tk()
root.title("Steve's simple text editor.")
root.config(bg='lightblue')
textwindow=Text(root,background='white')
textwindow.pack()
btn=Button(root,text='Append ',command=save_changes)
btn.pack()

btn2=Button(root,text="Show ", command=loadletter)
btn2.pack()

btn3=Button(root,text="Clear ", command=cleargui)
btn3.pack()

showtext()

root.mainloop()

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Biking helps me to cope with life.