jeudi 26 novembre 2020

Python using tkcalendar and getting the results from textfile

My question: is it possible to make a calendar by using tkcalendar that when I press the button on a specific date information from a textfile appears?

The text-file before splitted into many text-files:

days.txt:

Today is 2020/11/26

Soccer :

Today is 2020/11/27

Basketball :

...

Today is 2021/11/26

Run

:

The different textfiles after splitted:

day1.txt:

Today is 2020/11/26

Soccer

day2.txt:

Today is 2020/11/27

Basketball

...

day364.txt:

Today is 2021/11/26

Run

enter code here

from tkinter import *
from tkcalendar import *
import datetime

#Function that makes a textfile turn into 365 textfiles one for each day:
with open('days.txt', 'r') as f:
    split_alph = f.read().split(':\n')
    for i in range(len(split_alph)):
        x = open(f"day{i}", "w")
        x.write(split_alph[i])
        x.close()

root = Tk()
root.title('Hi')
root.geometry('500x400')

cal = Calendar(root, date_pattern="d/m/y", year = 2020, month = 11, day =1)
cal.pack(pady=20)

def grab_date():
    my_label.config(text = cal.get_date())
    d = cal.get_date()

#Some statement that when pressing date I want the label appear with 
#information 
#from the textfiles depending on what I press on.
#I want it to appear once. For example: if I press on the button with date 
#2020/11/26 I only want the information from day0.txt to appear once.

my_button = Button(root, text = 'Get date', command = grab_date)
my_button.pack()

my_label = Label(root, text = ' ')
my_label.pack(pady = 20)

root.mainloop()

Aucun commentaire:

Enregistrer un commentaire