下边资料是关于python通过Tkinter库实现的一个简单的文本编辑器的内容。
from tkSimpleDialog import askstring
from tkFileDialog import asksaveasfilename
from tkMessageBox import askokcancel
class Quitter(Frame):
def init(self, parent=None):
Frame.init(self, parent)
self.pack()
widget = Button(self, text=‘Quit’, command=self.quit)
widget.pack(expand=YES, fill=BOTH, side=LEFT)
def quit(self):
ans = askokcancel(‘Verify exit’, “Really quit?”)
if ans: Frame.quit(self)
class ScrolledText(Frame):
def init(self, parent=None, text=’’, file=None):
Frame.init(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makewidgets()
self.settext(text, file)
def makewidgets(self):
sbar = Scrollbar(self)
text = Text(self, relief=SUNKEN)
sbar.config(command=text.yview