Coding/Python 삽질기2008. 9. 17. 23:37
#-*- coding: cp949 -*-
# 메모장
from Tkinter import *
import tkMessageBox
import os.path
 
filename = "data.txt"
def ClearText():
    text.delete(1.0, END)  
   
def AppendData():
    textData = text.get(1.0, END).encode('cp949')
    tempFileData = ""
   
    if os.path.exists(filename):
        fp = open(filename, 'r')
        tempFileData = fp.read()
        fp.close()
   
    fp = open(filename, 'w')
    fp.write(textData)
    fp.write(tempFileData)
    fp.close()

def LoadData():
    if os.path.exists(filename):
        fp = open(filename, 'r')
        tempFileData = fp.read()
        fp.close()
   
        text.insert(1.0, tempFileData.decode('cp949'))   
   
def SaveData():
    textData = text.get(1.0, END).encode('cp949')
   
    fp = open(filename, 'w')
    fp.write(textData)
    fp.close()
       
def ShowInfo():
    tkMessageBox.showinfo("Information","http://chobocho.com\nVersion 0.2")
   
   
#----------------------------------------------------------
# main
if __name__ == "__main__":     
    root = Tk()
   
    text = Text(root, width=50, height = 20)
    text.pack()
    append_button  = Button(root, text="Append", command = AppendData)
    save_button  = Button(root, text="Save", command = SaveData)
    clear_button = Button(root, text="Clear", command = ClearText)
    load_button = Button(root, text="Load", command = LoadData)
    info_button = Button(root, text="Info", command = ShowInfo)

    info_button.pack(side=RIGHT)
    load_button.pack(side=RIGHT)
    clear_button.pack(side=RIGHT)
    save_button.pack(side=RIGHT)
    append_button.pack(side=RIGHT)

    root.mainloop()


사용자 삽입 이미지

'Coding > Python 삽질기' 카테고리의 다른 글

[조각코드] 숫자 배열 읽어서 리스트에 저장하는 코드  (0) 2008.10.06
간단한 메모장2  (0) 2008.09.17
간단한 메모장  (0) 2008.09.14
Fractal Tree  (0) 2008.06.21
Posted by chobocho

댓글을 달아 주세요