TKInter Sample Code
# Python & TkInter sample code, not great code though.
# simple demo text editor, to make markup possible
from Tkinter import *
import sys
InFileName = "c:/XMLTEST/foo.xml"
OutFileName = "c:/XMLTEST/bar.xml"
def die():
sys.exit(0)
class editor:
def __init__(self):
self.root = Tk()
root = self.root
self.text = Text(root)
self.text.pack()
self.qbutton = Button(root)
self.qbutton["command"] = die
self.qbutton["text"] = "Quit"
self.qbutton.pack()
self.lbutton = Button(root)
self.lbutton["command"] = self.load
self.lbutton["text"] = "Load"
self.lbutton.pack()
self.sbutton = Button(root)
self.sbutton["command"] = self.save
self.sbutton["text"] = "Save"
self.sbutton.pack()
self.mbutton = Button(root)
self.mbutton["command"] = self.markup
self.mbutton["text"] = "Markup"
self.mbutton.pack()
root.mainloop()
def save(self):
self.save_file(OutFileName)
def load(self):
self.load_file(
def markup(self): % just a fixed markup for demo purposes
self.text.insert(SEL_FIRST,'<keyword>')% insert before selection
self.text.insert(SEL_LAST,'</keyword>')% insert after selection
def load_file(self,FileName):
self.filename = FileName
try:
self.ifp = open(FileName, "r")
except:
print "Could not load",Filename
while(1):
line = self.ifp.readline()
if not line:
break
self.text.insert(INSERT,line)
self.ifp.close()
def save_file(self,FileName):
try:
self.ofp = open(FileName, "w")
except:
print "Could not open",Filename,"for writing"
contents = self.text.get("1.0",END)
self.ofp.write(contents)
self.ofp.close()
Ed = editor()