[소스]
#edit.py
#encoding=utf-8
from Tkinter import *
from tkFileDialog import *
from tkMessageBox import *
class MyEdit(Frame):
def __init__(self, root=Tk()):
Frame.__init__(self, root)
self.pack(expand=YES, fill=BOTH)
self.createWidgets()
self.onNew()
#root.protocol("WM_DELETE_WINDOW", self.onExit)
self.root=root
def createWidgets(self):
self.menubar=Menu(self)
self.master.config(menu=self.menubar)
file = Menu(self.menubar)
file.add_command(label='새로 만들기', command=self.onNew)
file.add_command(label='열기', command=self.onOpen)
file.add_command(label='저장', command=self.onSave)
file.add_command(label='다른이름으로 저장...', command=self.onSaveAs)
file.add_separator()
file.add_command(label='끝내기', command=self.onExit)
self.menubar.add_cascade(label='파일', menu=file)
help=Menu(self.menubar)
help.add_command(label='낙서장 정보', command=self.onAbout)
self.menubar.add_cascade(label='도움말', menu=help)
self.text=tbox=Text(self, relief=SUNKEN)
sbar=Scrollbar(self)
sbar.config(command=tbox.yview)
tbox.config(yscrollcommand=sbar.set)
tbox.config(font=('courier', 9, 'normal'))
sbar.pack(side=RIGHT, fill=Y)
tbox.pack(side=LEFT, expand=YES, fill=BOTH)
tbox.focus()
def onNew(self):
self.file=None
self.text.delete('1.0', END)
self.master.title('낙서장')
def onOpen(self):
self.file=askopenfilename()
if self.file:
text=open(self.file, 'r').read()
text=unicode(text, 'mbcs').encode('utf-8')
self.text.delete('1.0', END)
self.text.insert('1.0', text)
self.text.focus()
self.master.title(self.file+'-낙서장')
def onSave(self):
self.onSaveAs(self.file)
def onSaveAs(self, currfile=None):
filename=currfile or asksaveasfilename()
if filename:
text=self.text.get('1.0', END+'-1c')
text=text.encode('mbcs')
open(filename, 'w').write(text)
self.file=filename
self.master.title(self.file+'-낙서장')
def onExit(self):
self.root.destroy()
self.root.quit()
def onAbout(self):
showinfo('낙서장', '낙서장\n', '만든 날 : 2011년 8월 31일 \n' '만든 이 : lexlove')
if __name__ == '__main__' : MyEdit().mainloop()
#edit.py
#encoding=utf-8
from Tkinter import *
from tkFileDialog import *
from tkMessageBox import *
class MyEdit(Frame):
def __init__(self, root=Tk()):
Frame.__init__(self, root)
self.pack(expand=YES, fill=BOTH)
self.createWidgets()
self.onNew()
#root.protocol("WM_DELETE_WINDOW", self.onExit)
self.root=root
def createWidgets(self):
self.menubar=Menu(self)
self.master.config(menu=self.menubar)
file = Menu(self.menubar)
file.add_command(label='새로 만들기', command=self.onNew)
file.add_command(label='열기', command=self.onOpen)
file.add_command(label='저장', command=self.onSave)
file.add_command(label='다른이름으로 저장...', command=self.onSaveAs)
file.add_separator()
file.add_command(label='끝내기', command=self.onExit)
self.menubar.add_cascade(label='파일', menu=file)
help=Menu(self.menubar)
help.add_command(label='낙서장 정보', command=self.onAbout)
self.menubar.add_cascade(label='도움말', menu=help)
self.text=tbox=Text(self, relief=SUNKEN)
sbar=Scrollbar(self)
sbar.config(command=tbox.yview)
tbox.config(yscrollcommand=sbar.set)
tbox.config(font=('courier', 9, 'normal'))
sbar.pack(side=RIGHT, fill=Y)
tbox.pack(side=LEFT, expand=YES, fill=BOTH)
tbox.focus()
def onNew(self):
self.file=None
self.text.delete('1.0', END)
self.master.title('낙서장')
def onOpen(self):
self.file=askopenfilename()
if self.file:
text=open(self.file, 'r').read()
text=unicode(text, 'mbcs').encode('utf-8')
self.text.delete('1.0', END)
self.text.insert('1.0', text)
self.text.focus()
self.master.title(self.file+'-낙서장')
def onSave(self):
self.onSaveAs(self.file)
def onSaveAs(self, currfile=None):
filename=currfile or asksaveasfilename()
if filename:
text=self.text.get('1.0', END+'-1c')
text=text.encode('mbcs')
open(filename, 'w').write(text)
self.file=filename
self.master.title(self.file+'-낙서장')
def onExit(self):
self.root.destroy()
self.root.quit()
def onAbout(self):
showinfo('낙서장', '낙서장\n', '만든 날 : 2011년 8월 31일 \n' '만든 이 : lexlove')
if __name__ == '__main__' : MyEdit().mainloop()
'Python > 파이썬 프로그래밍 연습' 카테고리의 다른 글
wxPython 으로 GUI 프로그램 만들기 - wxGlade (1) | 2012.04.25 |
---|---|
wxPython 으로 GUI 프로그램 만들기 - 환경 갖추기 (0) | 2012.04.25 |
Tkinter GUI 프로그래밍 (0) | 2012.04.24 |
사건 주도적 프로그래밍 (0) | 2012.04.24 |
객체 지향 프로그래밍 (0) | 2012.04.24 |
댓글