간단한 일정 관리(To Do List) 만들기

image

from tkinter import *
from tkcalendar import Calendar, DateEntry
import datetime, os

save_folder = "./memo"

def save() :
    path = save_folder + "/" + nday.get()
    #print(path, day_text.get(1.0,END))
    with open(path, "w") as file :
        file.write(day_text.get(1.0, END))
    file.close()

def day_clicked(event) :
    
    try :
        day_text.delete(1.0, END)   
        nday.set(event.widget.get_date())
        day_label.update()
        path = save_folder + "/" + nday.get()
        
        with open(path, "r") as file :
            strings = file.readlines()
            for s in strings :
                day_text.insert(END, s)
    except :
        pass
    
    
root = Tk()

if not os.path.exists(save_folder) :
        os.mkdir(save_folder)
else :
    pass

root.title("일정관리")
root.geometry("650x300")

cal_label_frame = LabelFrame(root, text="달력")
cal_label_frame.pack(padx=5, pady=5, fill="both", expand=True, side="left")
memo_label_frame = LabelFrame(root, text="메모")
memo_label_frame.pack(padx=5, pady=5, fill="both", expand=True, side="left")
today = datetime.date.today()
cal = Calendar(cal_label_frame, selectmode="day", year=today.year, month=today.month, day=today.day)
cal.pack(padx=5, pady=5, fill = "both", expand = True)
cal.bind("<<CalendarSelected>>", day_clicked)

nday = StringVar()
nday.set(cal.get_date())
day_label = Label(memo_label_frame, textvariable=nday)
day_text = Text(memo_label_frame)
btn_save = Button(memo_label_frame, text="저장", command=save)

day_label.pack(side="top")
btn_save.pack(fill="x", expand=True, side="bottom")
day_text.pack(padx=2, pady=2, side="top")

#########################################################
path = save_folder + "/" + cal.get_date()
with open(path, "r") as file :
    strings = file.readlines()
    for s in strings :
        day_text.insert(END, s)
#########################################################

root.mainloop()

댓글남기기