create a tkinter window with a calendar and to do list in python

To create a tkinter window with a calendar and to-do list, we first need to import the necessary libraries.

main.py
import tkinter as tk
import calendar
37 chars
3 lines

Next, we can create a tkinter window and add a calendar widget to it.

main.py
app = tk.Tk()

cal = calendar.Calendar()
year, month = 2021, 9
days = cal.itermonthdays(year, month)

for day in days:
    label = tk.Label(app, text=day)
    label.pack()
172 chars
10 lines

In the code above, we use the calendar library to generate the days in the specified month and year, and then create a Label widget for each day in the calendar.

Next, we can create a to-do list widget using a Text widget.

main.py
todo_list = tk.Text(app, height=8, width=30)
todo_list.pack()
62 chars
3 lines

Finally, we can add a button to save the to-do list to a file.

main.py
def save_todo_list():
    with open('todo.txt', 'w') as f:
        f.write(todo_list.get('1.0', tk.END))

save_button = tk.Button(app, text='Save', command=save_todo_list)
save_button.pack()
191 chars
7 lines

In the code above, we define a function save_todo_list which saves the contents of the to-do list to a file named todo.txt. We then create a Button widget that calls this function when clicked.

Putting it all together, we get the following code:

main.py
import tkinter as tk
import calendar

app = tk.Tk()

cal = calendar.Calendar()
year, month = 2021, 9
days = cal.itermonthdays(year, month)

for day in days:
    label = tk.Label(app, text=day)
    label.pack()

todo_list = tk.Text(app, height=8, width=30)
todo_list.pack()

def save_todo_list():
    with open('todo.txt', 'w') as f:
        f.write(todo_list.get('1.0', tk.END))

save_button = tk.Button(app, text='Save', command=save_todo_list)
save_button.pack()

app.mainloop()
481 chars
25 lines

This code creates a window with a calendar widget and a to-do list widget, as well as a "Save" button. When the button is clicked, the contents of the to-do list are saved to a file named todo.txt.

gistlibby LogSnag