I'm trying to make a calendar with Python Tkinter where I can make entries and save those with the date I choose. To save them I use a dictionary in that I could make more than 1 entry. (If there is another way please tell me)How can I now define which entry I want to display on the screen Like when one entry is 20.02.2023: Dentist and the other is 12.02.2023: Doctor? How can I display f.e the Doctor? I use the Tkinter calendar preset so I didn't make the calendar by myself so I save my date with the get. date function but in the end, it comes to the same. I am also not sure if I should use two dictionary's or 1 so for the date one and the entry one or for both the same.
Here is a simplified version of my code:
from tkinter import*
from tkcalendar import *
import datetime
from tkinter.ttk import *
root = Tk()
root.title("Calendar")
root.attributes("-fullscreen", True)
dictionary_date = {}
dictionary_entry = {}
#here it doesnt work and I really dont know how to fix it
def output_entry():
if date == cal.get_date():
label.config(text="Today is the" + str(cal.get_date()) + " und your entry is: " + str(dictionary_entry))
else:
label.config(text="You have no entry today")
def save_entry():
global date
entry_information = entry.get()
date = cal.get_date()
dictionary_date[""] = date
dictionary_entry[""] = entry_information
# this is the code for the calendar itself
today = datetime.date.today()
cal = Calendar(root, selectmode="day", year=today.year, month=today.month, day=today.day)
Calendar.date.day
cal.pack(fill="both", expand=True)
#Code for the entry and the label where the entry should stand
entry = Entry(root, width=35)
entry.pack()
label = Label(root, text="")
label.pack(pady=20)
button_save = Button(root, text="Save Entry with date", command=save_entry)
button_save.pack()
button_output = Button(root, text= "Get Entry and Date", command= output_entry)
button_output.pack()
root.mainloop()
Like you see I cant get both dictionary and can't get both informations.
If I understand correctly, it seems to me that you can get away with using a single dictionary with the key:value structure of
{date:entry}
. Note that dictionary keys in Python have to be strings, while their values can be just about any type.To that end, when you're saving an entry you would just convert the date specified into a
str
ing to act as the 'key' and save theentry_information
as the 'value'.Note that as written, only one event can be saved on a given date. Calling
save_entry
on the same date more than once will overwrite any existing values incalendar_dict