-1

I'm quite new to programming and I got the task to create a temperature overview program. I decided to create a calendar to easily overview every month. Every day in the month that I am view should read a text file for the specific day. It should count the lines there were made and count a specific value and above to get a percentage. With that percentage we could add red in the background of the specific day. On click it should open an graph program with exact that file, I already programmed

Now I'm stuck at that the program should find those days I am viewing to begin to read the text files to calculate the "red" color.

Here is the code so far:

PS: My coding knowledge is based on about 4 days...

from tkinter import *
from tkcalendar import *
import tkcalendar
import tkinter
from tkinter import messagebox
from datetime import date                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               


#root =Tk()

def cal_func():
    def calval():
        de = DateEntry
        tag = 1
        counter = 0
        for i in range(1, 31):
            #??????
            counter + 1

    cal = Calendar(
        background="grey",
        normalbackground="white",
        font="Arial 20",
        weekendbackground="lightgray",
        selectmode="day",
        year=date.today().year,
        month=date.today().month,
        day=date.today().day
    )

    cal.pack(expand=True, fill="both")
    btn3 = Button(text="Aktualisieren", command=calval)
    btn3.pack()

cal_func()

mainloop()
accdias
  • 5,160
  • 3
  • 19
  • 31
JymaXx
  • 1
  • Does this answer your question? [How to get the selected date for DateEntry in tkcalendar (Python)?](https://stackoverflow.com/questions/50625818/how-to-get-the-selected-date-for-dateentry-in-tkcalendar-python) – stovfl Feb 24 '20 at 14:52
  • Poorly not, I found this thread earlier this day and I tried these functions, the problem is, that it's not just one date I need to "get", it should be automated and not an user based function, to read the files for the specific date. Maybe my request is kind to special I think... – JymaXx Feb 24 '20 at 14:58
  • ***"my request is kind to special ... should be automated"***: You hava a `Button`, that is ***user based***? Where did you get the `data` from? Do you want the opposite [tkinter-tkcalendar-to-display-events](https://stackoverflow.com/questions/52515099) – stovfl Feb 24 '20 at 15:04
  • Maybe you can find what you are looking for in the doc https://tkcalendar.readthedocs.io/en/stable/Calendar.html#virtual-events: There is a virtual event, `<>`, which is triggered when the user selects a date so you can bind a function to display all your data when a day is clicked. – j_4321 Feb 24 '20 at 15:58

1 Answers1

2

You want to know when the user selects a day to display the corresponding data. This is possible through bindings. The <<CalendarSelected>> event is triggered each time a new day is selected. So you can bind a function to this event. In this function (display_day() in the code below) you can retrieve the selected day with either get_date() or selection_get() and then load your data from your file and display the graph.

import tkcalendar
import tkinter as tk
from tkinter import ttk

def display_day(event):
    day = cal.get_date() # you can use cal.selection_get() to get the date
                         # as a datetime.date
    display.configure(text=f"Selected day is {day}")  # replace by your code to load data 
                                                      # and display graph

root = tk.Tk()
cal = tkcalendar.Calendar(root, background="grey", normalbackground="white",
                          font="Arial 20",
                          weekendbackground="lightgray",
                          selectmode="day")
cal.pack()
display = ttk.Label(root, text="Selected day is ")
display.pack()
cal.bind("<<CalendarSelected>>", display_day)
root.mainloop()
j_4321
  • 15,431
  • 3
  • 34
  • 61