Ejemplo n.º 1
0
    def get_calendar(self):
        print('in get_calendar app')
        window = tk.Tk()
        cal = Calendar(window)
        year = time.localtime(time.time())[0]
        month = time.localtime(time.time())[1]
        date = time.localtime(time.time())[2]

        if month == 12:
            cal.config(mindate=datetime.date(year, month, date),
                       maxdate=datetime.date(year, 1, date))
        elif month == 1 and date > 28:
            cal.config(mindate=datetime.date(year, month, date),
                       maxdate=datetime.date(year, month + 1, 28))
        else:
            try:
                cal.config(mindate=datetime.date(year, month, date),
                           maxdate=datetime.date(year, month + 1, date))
            except ValueError:
                cal.config(mindate=datetime.date(year, month, date),
                           maxdate=datetime.date(year, month + 1, date - 1))

        cal.config(showweeknumbers=False,
                   disabledbackground='red',
                   disabledforeground='blue',
                   disabledselectbackground='pink',
                   disabledselectforeground='purple',
                   disableddaybackground='red')
        cal.pack()

        select_button = tk.Button(cal,
                                  text='Select Date',
                                  command=lambda: print(cal.selection_get()))
        select_button.pack()
        cal.mainloop()
Ejemplo n.º 2
0
    def test_calendar_buttons_functions(self):
        widget = Calendar(self.window)
        widget.pack()
        widget._prev_month()
        widget._next_month()
        widget._prev_year()
        widget._next_year()
        widget._remove_selection()
        widget.selection_set(format_date(date(2018, 12, 31), 'short'))
        self.assertEqual(widget.selection_get(), date(2018, 12, 31))
        with self.assertRaises(ValueError):
            widget.selection_set("ab")
        widget.selection_set(None)
        self.assertIsNone(widget.selection_get())
        widget.selection_set(date(2015, 12, 31))
        self.assertEqual(widget.selection_get(), date(2015, 12, 31))

        widget.config(selectmode='none')
        self.assertIsNone(widget.selection_get())
        l = ttk.Label(widget, text="12")
        widget._on_click(TestEvent(widget=l))
        self.assertIsNone(widget.selection_get())
        self.window.update()
        widget.config(selectmode='day')
        l = ttk.Label(widget, text="12")
        widget._on_click(TestEvent(widget=l))
        self.window.update()
        self.assertEqual(widget.selection_get(), date(2015, 12, 12))
        widget.config(state='disabled')
        l = ttk.Label(widget, text="14")
        widget._on_click(TestEvent(widget=l))
        self.window.update()
        self.assertEqual(widget.selection_get(), date(2015, 12, 12))
Ejemplo n.º 3
0
    def test_calendar_buttons_functions(self):
        widget = Calendar(self.window)
        widget.pack()
        widget._prev_month()
        widget._next_month()
        widget._prev_year()
        widget._next_year()
        widget._remove_selection()
        widget.selection_set(datetime(2018, 12, 31).strftime('%x'))
        self.assertEqual(widget.selection_get(), datetime(2018, 12, 31))
        with self.assertRaises(ValueError):
            widget.selection_set("ab")
        widget.selection_set(None)
        self.assertIsNone(widget.selection_get())
        widget.selection_set(datetime(2015, 12, 31))
        self.assertEqual(widget.selection_get(), datetime(2015, 12, 31))

        widget.config(selectmode='none')
        self.assertIsNone(widget.selection_get())

        l = ttk.Label(widget, text="12")
        widget._on_click(TestEvent(widget=l))
Ejemplo n.º 4
0
    def test_calendar_get_set(self):
        widget = Calendar(self.window, foreground="red")
        widget.pack()
        self.window.update()

        options = [
            'cursor', 'font', 'borderwidth', 'state', 'selectmode',
            'textvariable', 'locale', 'showweeknumbers', 'selectbackground',
            'selectforeground', 'disabledselectbackground',
            'disabledselectforeground', 'normalbackground', 'normalforeground',
            'background', 'foreground', 'bordercolor', 'othermonthforeground',
            'othermonthbackground', 'othermonthweforeground',
            'othermonthwebackground', 'weekendbackground', 'weekendforeground',
            'headersbackground', 'headersforeground', 'disableddaybackground',
            'disableddayforeground'
        ]
        self.assertEqual(sorted(widget.keys()), sorted(options))

        with self.assertRaises(AttributeError):
            widget.cget("test")

        self.assertEqual(widget["foreground"], "red")
        widget["foreground"] = "blue"
        self.window.update()
        self.assertEqual(widget["foreground"], "blue")

        widget.config(cursor="watch")
        self.window.update()
        self.assertEqual(widget["cursor"], "watch")
        self.assertTrue(widget["showweeknumbers"])
        widget.config(showweeknumbers=False)
        self.window.update()
        self.assertFalse(widget["showweeknumbers"])
        self.assertFalse(widget._week_nbs[0].winfo_ismapped())
        widget.config(font="Arial 20 bold")
        self.window.update()
        self.assertEqual(widget["font"], "Arial 20 bold")
        widget.config(borderwidth=5)
        self.window.update()
        self.assertEqual(widget["borderwidth"], 5)
        with self.assertRaises(ValueError):
            widget.config(borderwidth="a")
        widget.config(selectmode="none")
        self.window.update()
        self.assertEqual(widget["selectmode"], "none")
        widget.config(selectmode="day")
        self.window.update()
        self.assertEqual(widget["selectmode"], "day")
        with self.assertRaises(ValueError):
            widget.config(selectmode="a")
        self.assertEqual(widget.cget('state'), tk.NORMAL)
        with self.assertRaises(ValueError):
            widget.config(state="test")
        with self.assertRaises(AttributeError):
            widget.config(locale="en_US.UTF-8")
        with self.assertRaises(AttributeError):
            widget.config(test="test")
        dic = {op: "yellow" for op in options[7:]}
        widget.configure(**dic)
        self.window.update()
        for op in options[7:]:
            self.assertEqual(widget.cget(op), "yellow")
#Calendar Settings
cal = Calendar(root,
               font="fixedsys 14",
               selectmode="day",
               locale="en_US",
               cursor="sizing",
               background="white",
               disabledbackground="white",
               bordercolor="pink",
               headersbackground="bisque2",
               normalbackground="black",
               foreground="bisque4",
               normalforeground="bisque4",
               headersforeground="bisque4")

cal.config(background="black")
cal.grid(row=0, column=0, sticky="N", rowspan=9)
cal.bind("<<CalendarSelected>>", ListTodo)

#Variable Global
tanggal = str(cal.selection_get())

#Style
style = ttk.Style()
style.configure("Treeview", background="bisque4", foreground="bisque4")

treev = ttk.Treeview(root)
treev.grid(row=0, column=1, sticky="WNE", rowspan=4, columnspan=2)

#Scrollbar Settings
scrollBar = tk.Scrollbar(root, orient="vertical", command=treev.yview)
Ejemplo n.º 6
0
    def test_calendar_get_set(self):
        widget = Calendar(self.window,
                          foreground="red",
                          year=2010,
                          month=1,
                          day=3)
        widget.pack()
        self.window.update()

        options = [
            'cursor', 'font', 'borderwidth', 'state', 'selectmode',
            'textvariable', 'locale', 'date_pattern', 'mindate', 'maxdate',
            'firstweekday', 'weekenddays', 'showweeknumbers',
            'showothermonthdays', 'selectbackground', 'selectforeground',
            'disabledselectbackground', 'disabledselectforeground',
            'normalbackground', 'normalforeground', 'background', 'foreground',
            'bordercolor', 'disabledbackground', 'disabledforeground',
            'othermonthforeground', 'othermonthbackground',
            'othermonthweforeground', 'othermonthwebackground',
            'weekendbackground', 'weekendforeground', 'headersbackground',
            'headersforeground', 'disableddaybackground',
            'disableddayforeground', 'tooltipbackground', 'tooltipforeground',
            'tooltipalpha', 'tooltipdelay'
        ]

        self.assertEqual(sorted(widget.keys()), sorted(options))

        with self.assertRaises(AttributeError):
            widget.cget("test")
        self.assertEqual(widget["foreground"], "red")
        widget["foreground"] = "blue"
        self.window.update()
        self.assertEqual(widget["foreground"], "blue")
        widget.configure({
            'foreground': 'cyan',
            'background': 'green'
        },
                         background="blue",
                         borderwidth=4)
        self.window.update()
        self.assertEqual(widget["foreground"], "cyan")
        self.assertEqual(widget["background"], "blue")
        self.assertEqual(widget["borderwidth"], 4)
        widget.config(locale='fr_FR')
        self.assertEqual(widget['locale'], 'fr_FR')
        self.assertEqual(widget._week_days[0].cget('text'), 'lun.')
        widget.config(locale='en_US')
        self.assertEqual(widget['locale'], 'en_US')
        self.assertEqual(widget._week_days[0].cget('text'), 'Mon')
        with self.assertRaises(UnknownLocaleError):
            widget.config(locale="jp")
        widget.config(cursor="watch")
        self.window.update()
        self.assertEqual(widget["cursor"], "watch")
        self.assertTrue(widget["showweeknumbers"])
        self.assertNotEqual(widget._week_nbs[0].grid_info(), {})
        widget.config(showweeknumbers=False)
        self.window.update()
        self.assertFalse(widget["showweeknumbers"])
        self.assertEqual(widget._week_nbs[0].grid_info(), {})
        self.assertFalse(widget._week_nbs[0].winfo_ismapped())
        self.assertNotEqual(widget._calendar[-1][-1].cget('text'), '')
        self.assertTrue(widget["showothermonthdays"])
        widget.config(showothermonthdays=False)
        self.window.update()
        self.assertFalse(widget["showothermonthdays"])
        self.assertEqual(widget._calendar[-1][-1].cget('text'), '')
        widget.config(font="Arial 20 bold")
        self.window.update()
        self.assertEqual(widget["font"], "Arial 20 bold")
        widget.config(borderwidth=5)
        self.window.update()
        self.assertEqual(widget["borderwidth"], 5)
        with self.assertRaises(ValueError):
            widget.config(borderwidth="a")
        widget.config(firstweekday='sunday')
        self.window.update()
        self.assertEqual(widget["firstweekday"], 'sunday')
        with self.assertRaises(ValueError):
            widget.config(firstweekday="a")

        widget.config(weekenddays=[5, 7])
        self.window.update()
        we_style = 'we.%s.TLabel' % widget._style_prefixe
        normal_style = 'normal.%s.TLabel' % widget._style_prefixe
        for i in range(7):
            self.assertEqual(widget._calendar[0][i].cget('style'), we_style if
                             (i + 1) in [5, 7] else normal_style)

        widget["mindate"] = datetime(2018, 9, 10)
        self.assertEqual(widget["mindate"], date(2018, 9, 10))
        widget.selection_set(date(2018, 9, 23))
        self.window.update()
        i, j = widget._get_day_coords(date(2018, 9, 2))
        self.assertIn('disabled', widget._calendar[i][j].state())
        i, j = widget._get_day_coords(date(2018, 9, 21))
        self.assertNotIn('disabled', widget._calendar[i][j].state())
        self.assertIn('disabled', widget._l_month.state())
        self.assertIn('disabled', widget._l_year.state())
        i, j = widget._get_day_coords(date(2018, 9, 10))
        self.assertNotIn('disabled', widget._calendar[i][j].state())
        i, j = widget._get_day_coords(date(2018, 9, 9))
        self.assertIn('disabled', widget._calendar[i][j].state())
        with self.assertRaises(TypeError):
            widget.config(mindate="a")
        self.assertEqual(widget["mindate"], date(2018, 9, 10))
        widget["mindate"] = None
        self.window.update()
        self.assertIsNone(widget["mindate"])
        i, j = widget._get_day_coords(date(2018, 9, 2))
        self.assertNotIn('disabled', widget._calendar[i][j].state())
        self.assertNotIn('disabled', widget._l_month.state())
        self.assertNotIn('disabled', widget._l_year.state())

        widget["maxdate"] = datetime(2018, 9, 10)
        self.assertEqual(widget["maxdate"], date(2018, 9, 10))
        widget.selection_set(date(2018, 9, 2))
        self.window.update()
        i, j = widget._get_day_coords(date(2018, 9, 22))
        self.assertIn('disabled', widget._calendar[i][j].state())
        i, j = widget._get_day_coords(date(2018, 9, 4))
        self.assertNotIn('disabled', widget._calendar[i][j].state())
        self.assertIn('disabled', widget._r_month.state())
        self.assertIn('disabled', widget._r_year.state())
        i, j = widget._get_day_coords(date(2018, 9, 10))
        self.assertNotIn('disabled', widget._calendar[i][j].state())
        i, j = widget._get_day_coords(date(2018, 9, 11))
        self.assertIn('disabled', widget._calendar[i][j].state())
        with self.assertRaises(TypeError):
            widget.config(maxdate="a")
        self.assertEqual(widget["maxdate"], date(2018, 9, 10))
        widget["maxdate"] = None
        self.window.update()
        self.assertIsNone(widget["maxdate"])
        i, j = widget._get_day_coords(date(2018, 9, 22))
        self.assertNotIn('disabled', widget._calendar[i][j].state())
        self.assertNotIn('disabled', widget._r_month.state())
        self.assertNotIn('disabled', widget._r_year.state())

        widget.config(selectmode="none")
        self.window.update()
        self.assertEqual(widget["selectmode"], "none")
        widget.config(selectmode="day")
        self.window.update()
        self.assertEqual(widget["selectmode"], "day")
        with self.assertRaises(ValueError):
            widget.config(selectmode="a")
        self.assertEqual(widget.cget('state'), tk.NORMAL)
        with self.assertRaises(ValueError):
            widget.config(state="test")
        widget['date_pattern'] = 'MM/dd/yyyy'
        self.window.update()
        self.assertEqual(widget["date_pattern"], 'MM/dd/yyyy')
        with self.assertRaises(ValueError):
            widget.config(date_pattern="mm-dd-cc")
        with self.assertRaises(AttributeError):
            widget.config(test="test")
        dic = {op: "yellow" for op in options[12:-4]}
        widget.configure(**dic)
        self.window.update()
        for op in options[12:-4]:
            self.assertEqual(widget.cget(op), "yellow")
        widget.config(tooltipalpha=0.5)
        self.assertEqual(widget["tooltipalpha"], 0.5)
        self.assertEqual(widget.tooltip_wrapper["alpha"], 0.5)
        widget.config(tooltipdelay=1000)
        self.assertEqual(widget["tooltipdelay"], 1000)
        self.assertEqual(widget.tooltip_wrapper["delay"], 1000)
        widget.config(tooltipforeground='black')
        self.assertEqual(widget["tooltipforeground"], 'black')
        widget.config(tooltipbackground='cyan')
        self.assertEqual(widget["tooltipbackground"], 'cyan')
Ejemplo n.º 7
0
    def test_calendar_get_set(self):
        widget = Calendar(self.window, foreground="red")
        widget.pack()
        self.window.update()

        options = [
            'cursor', 'font', 'borderwidth', 'state', 'selectmode',
            'textvariable', 'locale', 'firstweekday', 'showweeknumbers',
            'showothermonthdays', 'selectbackground', 'selectforeground',
            'disabledselectbackground', 'disabledselectforeground',
            'normalbackground', 'normalforeground', 'background', 'foreground',
            'bordercolor', 'othermonthforeground', 'othermonthbackground',
            'othermonthweforeground', 'othermonthwebackground',
            'weekendbackground', 'weekendforeground', 'headersbackground',
            'headersforeground', 'disableddaybackground',
            'disableddayforeground', 'tooltipbackground', 'tooltipforeground',
            'tooltipalpha', 'tooltipdelay'
        ]

        self.assertEqual(sorted(widget.keys()), sorted(options))

        with self.assertRaises(AttributeError):
            widget.cget("test")

        self.assertEqual(widget["foreground"], "red")
        widget["foreground"] = "blue"
        self.window.update()
        self.assertEqual(widget["foreground"], "blue")

        widget.config(cursor="watch")
        self.window.update()
        self.assertEqual(widget["cursor"], "watch")
        self.assertTrue(widget["showweeknumbers"])
        self.assertNotEqual(widget._week_nbs[0].grid_info(), {})
        widget.config(showweeknumbers=False)
        self.window.update()
        self.assertFalse(widget["showweeknumbers"])
        self.assertEqual(widget._week_nbs[0].grid_info(), {})
        self.assertFalse(widget._week_nbs[0].winfo_ismapped())
        self.assertNotEqual(widget._calendar[-1][-1].cget('text'), '')
        self.assertTrue(widget["showothermonthdays"])
        widget.config(showothermonthdays=False)
        self.window.update()
        self.assertFalse(widget["showothermonthdays"])
        self.assertEqual(widget._calendar[-1][-1].cget('text'), '')
        widget.config(font="Arial 20 bold")
        self.window.update()
        self.assertEqual(widget["font"], "Arial 20 bold")
        widget.config(borderwidth=5)
        self.window.update()
        self.assertEqual(widget["borderwidth"], 5)
        with self.assertRaises(ValueError):
            widget.config(borderwidth="a")
        widget.config(firstweekday='sunday')
        self.window.update()
        self.assertEqual(widget["firstweekday"], 'sunday')
        with self.assertRaises(ValueError):
            widget.config(firstweekday="a")
        widget.config(selectmode="none")
        self.window.update()
        self.assertEqual(widget["selectmode"], "none")
        widget.config(selectmode="day")
        self.window.update()
        self.assertEqual(widget["selectmode"], "day")
        with self.assertRaises(ValueError):
            widget.config(selectmode="a")
        self.assertEqual(widget.cget('state'), tk.NORMAL)
        with self.assertRaises(ValueError):
            widget.config(state="test")
        with self.assertRaises(AttributeError):
            widget.config(locale="en_US.UTF-8")
        with self.assertRaises(AttributeError):
            widget.config(test="test")
        dic = {op: "yellow" for op in options[8:-4]}
        widget.configure(**dic)
        self.window.update()
        for op in options[8:-4]:
            self.assertEqual(widget.cget(op), "yellow")
        widget.config(tooltipalpha=0.5)
        self.assertEqual(widget["tooltipalpha"], 0.5)
        self.assertEqual(widget.tooltip_wrapper["alpha"], 0.5)
        widget.config(tooltipdelay=1000)
        self.assertEqual(widget["tooltipdelay"], 1000)
        self.assertEqual(widget.tooltip_wrapper["delay"], 1000)
        widget.config(tooltipforeground='black')
        self.assertEqual(widget["tooltipforeground"], 'black')
        widget.config(tooltipbackground='cyan')
        self.assertEqual(widget["tooltipbackground"], 'cyan')
Ejemplo n.º 8
0
                       anchor="n")
select_date_lb.grid(row=current_row, column=0)

current_row = current_row + 1

start_date_lb = Label(main_window, text="From: ", font=(None, 18), anchor="n")
start_date_lb.grid(row=current_row, column=0)

start_date = Calendar(main_window,
                      selectmode="day",
                      selectforeground="red",
                      foreground="blue",
                      background="gray",
                      headersforeground="black",
                      showweeknumbers=False)
start_date.config(maxdate=start_date.datetime.now())
start_date.grid(row=current_row, column=1)

end_date_lb = Label(main_window, text="To: ", font=(None, 18), anchor="n")
end_date_lb.grid(row=current_row, column=2)

end_date = Calendar(main_window,
                    selectmode="day",
                    selectforeground="red",
                    foreground="blue",
                    background="gray",
                    headersforeground="black",
                    showweeknumbers=False)
end_date.config(maxdate=end_date.datetime.now())
end_date.grid(row=current_row, column=3)
Ejemplo n.º 9
0
    def test_calendar_get_set(self):
        widget = Calendar(self.window, foreground="red")
        widget.pack()
        self.window.update()

        options = [
            'cursor', 'font', 'borderwidth', 'selectmode', 'locale',
            'selectbackground', 'selectforeground', 'normalbackground',
            'normalforeground', 'background', 'foreground', 'bordercolor',
            'othermonthforeground', 'othermonthbackground',
            'othermonthweforeground', 'othermonthwebackground',
            'weekendbackground', 'weekendforeground', 'headersbackground',
            'headersforeground'
        ]
        self.assertEqual(sorted(widget.keys()), sorted(options))

        with self.assertRaises(AttributeError):
            widget.cget("test")

        self.assertEqual(widget["foreground"], "red")
        widget["foreground"] = "blue"
        self.window.update()
        self.assertEqual(widget["foreground"], "blue")

        widget.config(cursor="watch")
        self.window.update()
        self.assertEqual(widget["cursor"], "watch")
        widget.config(font="Arial 20 bold")
        self.window.update()
        self.assertEqual(widget["font"], "Arial 20 bold")
        widget.config(borderwidth=5)
        self.window.update()
        self.assertEqual(widget["borderwidth"], 5)
        with self.assertRaises(ValueError):
            widget.config(borderwidth="a")
        widget.config(selectmode="none")
        self.window.update()
        self.assertEqual(widget["selectmode"], "none")
        widget.config(selectmode="day")
        self.window.update()
        self.assertEqual(widget["selectmode"], "day")
        with self.assertRaises(ValueError):
            widget.config(selectmode="a")
        with self.assertRaises(AttributeError):
            widget.config(locale="en_US.UTF-8")
        with self.assertRaises(AttributeError):
            widget.config(test="test")
        dic = {op: "yellow" for op in options[5:]}
        widget.configure(**dic)
        self.window.update()
        for op in options[5:]:
            self.assertEqual(widget.cget(op), "yellow")
def open():
    global cal, end_button, pick_button, prev_date, root, startCal, endCal, startDate, endDate, CLUSTERS, CLUSTERS_NAMES, CLUSTERS_DATES, loop, flagaRandom, random_button, randtxt, startDate, endDate
    if not startDate:
        startDate = startCal.get_date()
        endDate = endCal.get_date()
    switch = True
    if checkProperDate(startDate, endDate) == 0:
        return
    CLUSTERS, CLUSTERS_NAMES, CLUSTERS_DATES = createClusters(
        startDate.timetuple().tm_yday,
        endDate.timetuple().tm_yday)
    root.destroy()
    root = tkinter.Tk()
    root.configure(background="white")
    root.title('Date Picker')
    img = tkinter.Image("photo", file="data/calendar.gif")
    root.tk.call('wm', 'iconphoto', root._w, img)

    style = ttk.Style(root)
    style.theme_use('default')
    root.geometry("1000x800")
    my_label = tkinter.Label(root, text="Select a date")
    cal = Calendar(root,
                   selectmode="day",
                   year=2021,
                   disabledbackground="red",
                   headersbackground="slateblue",
                   normalbackground="white",
                   weekendbackground="mediumpurple",
                   selectbackground="salmon",
                   showothermonthdays=False)
    cal.config(background="black")
    cal.pack(pady=20, fill="both", expand=True)
    prev_date = cal.get_date()

    def grab_date():
        global picked_ids
        picked_date = cal.get_date()
        # my_label.config(text="Picked Date " + picked_date)
        if picked_date == "":
            messagebox.showerror("Error", "First select a date!")
            return
        if datetime.strptime(picked_date,
                             "%m/%d/%y") not in picked_ids["dates"]:
            picked_ids["ids"].append(
                cal.calevent_create(datetime.strptime(picked_date, "%m/%d/%y"),
                                    "Not provided", 'message'))
            picked_ids["dates"].append(
                datetime.strptime(picked_date, "%m/%d/%y"))
            date_index = datetime.strptime(picked_date,
                                           "%m/%d/%y").timetuple().tm_yday
            picked_ids["indexes"].append(date_index)
        else:
            idx = picked_ids["dates"].index(
                datetime.strptime(picked_date, "%m/%d/%y"))
            id = picked_ids["ids"][idx]
            date = cal.calevents[id]['date']
            del cal.calevents[id]
            del cal._calevent_dates[date]
            cal._reset_day(date)
            picked_ids["ids"].pop(idx)
            picked_ids["dates"].pop(idx)
            picked_ids["indexes"].pop(idx)
            my_label.config(text="Selected date: None")
            global prev_date
            prev_date = None
            cal._sel_date = None

    def random_events_button():
        global picked_ids, endDate, startDate, cal, root, flagaRandom, randtxt, random_button
        if flagaRandom:
            ilosc = endDate.timetuple().tm_yday - startDate.timetuple(
            ).tm_yday + 1
            daty = np.unique(
                np.random.randint(startDate.timetuple().tm_yday,
                                  endDate.timetuple().tm_yday + 1,
                                  np.random.randint(1, ilosc + 1)))
            for data in daty:
                datatemp = (datetime(2021, 1, 1) + timedelta(int(data) - 1))
                if datatemp not in picked_ids["dates"]:
                    picked_ids["ids"].append(
                        cal.calevent_create(datatemp.date(), "Not provided",
                                            "message"))
                    picked_ids["dates"].append(datatemp)
                    picked_ids["indexes"].append(data)
            flagaRandom = False
            randtxt = "Remove all"
            # cal._display_calendar()
        else:
            flagaRandom = True
            randtxt = "Select random dates"
            cal.calevent_remove("all")
            picked_ids["ids"] = []
            picked_ids["dates"] = []
            picked_ids["indexes"] = []
        if pick_button.winfo_exists():
            random_button["text"] = randtxt

    def date_check():
        global prev_date, butText, pick_button, pick_button, startDate, endDate, after2
        if prev_date != cal.get_date():
            if cal.get_date() == "":
                my_label.config(text="Select a date")
            else:
                my_label.config(text="Selected date: " + cal.get_date())
            prev_date = cal.get_date()
        if cal.get_date() == "":
            butText = "Pick Date"
        elif datetime.strptime(cal.get_date(),
                               "%m/%d/%y") in picked_ids["dates"]:
            butText = "Unpick Date"
        else:
            butText = "Pick Date"
        if pick_button.winfo_exists():
            pick_button["text"] = butText
        if cal.get_date() != "":
            calendar_date = datetime.strptime(cal.get_date(),
                                              "%m/%d/%y").date()
            if calendar_date > endDate:
                messagebox.showerror(
                    "Error",
                    f"Selected date must be from {startDate.strftime('%d/%m/%Y')} to {endDate.strftime('%d/%m/%Y')}"
                )
                cal.selection_set(endDate)
            elif calendar_date < startDate:
                messagebox.showerror(
                    "Error",
                    f"Selected date must be from {startDate.strftime('%d/%m/%Y')} to {endDate.strftime('%d/%m/%Y')}"
                )
                cal.selection_set(startDate)
        after2 = root.after(100, date_check)

    def stop_selecting():
        global cal, end_button
        cal._remove_selection()
        cal.__setitem__("selectmode", "none")
        pick_button.destroy()
        random_button.destroy()
        end_button["text"] = "Show results"
        end_button["command"] = results
        dates = []
        for date in picked_ids["dates"]:
            dates.append(datetime.strftime(date, '%d/%m/%y'))
        dates = str(dates).replace('\'', '').replace(', ', ', ').replace(
            '[', '').replace(']', '')
        my_label.config(text=f"Selected dates: {dates}",
                        wraplength=1000,
                        justify="center")

    def results():
        global picked_ids, startDate, endDate, root, switch, img, loop, after2, CLUSTERS, CLUSTERS_NAMES, CLUSTERS_DATES, PRZEROBIONY, Top, restart_button
        # ustawienia okna
        switch = False
        root.after_cancel(loop)
        root.after_cancel(after2)
        Top = tkinter.Toplevel(root, )
        Top.configure(background="white")
        Top.title('Result')
        Top.grab_set()
        img = tkinter.Image("photo", file="data/calendar.gif")
        # root.tk.call('wm', 'iconphoto', root._w, img)
        style = ttk.Style(Top)
        style.theme_use('default')
        # # wyliczamy długość tablicy
        PERIODICITY = np.zeros(
            (endDate.timetuple().tm_yday - startDate.timetuple().tm_yday + 1),
            int)
        for i in range(PERIODICITY.shape[0]):
            PERIODICITY[i] = 0 if i + startDate.timetuple(
            ).tm_yday in picked_ids["indexes"] else i + startDate.timetuple(
            ).tm_yday  # UNIVERSE
        PERIODICITY = PERIODICITY[PERIODICITY[:] != 0]
        PRZEROBIONY = np.multiply(CLUSTERS, CLUSTERS_DATES).tolist()
        NPRZEROBIONY = []
        NNAZWY = []
        for i in range(len(PRZEROBIONY)):
            NNAZWY.append(CLUSTERS_NAMES[i])
            NPRZEROBIONY.append(set(filter((0).__ne__, PRZEROBIONY[i])))
        print("OKRES: ", PERIODICITY)
        # print("prze",NPRZEROBIONY)
        wyniki = problem(
            set(PERIODICITY.copy()),
            NPRZEROBIONY.copy(),
        )
        msg = ""
        przerywnik = "," if len(wyniki) > 2 else "plus"
        exception = ""
        exceptionplus = ""
        res = set([])
        for wynik in wyniki:
            idx = NPRZEROBIONY.index(wynik)
            # print(idx)
            if msg == "" and NNAZWY[idx][0] != "f":
                msg += "'" + NNAZWY[idx] + "'"
            elif msg == "" and NNAZWY[idx][0] == "f":
                msg += NNAZWY[idx][:5] + "'" + NNAZWY[idx][5:] + "'"
            elif NNAZWY[idx][0] == "f":
                msg += przerywnik + " " + NNAZWY[idx][:5] + "'" + NNAZWY[idx][
                    5:] + "'"
            else:
                msg += f" {przerywnik} '{NNAZWY[idx]}'"
            res = res | wynik
        if len(res - set(PERIODICITY)) > 0 or len(set(PERIODICITY) - res) > 0:
            diffs = []
            diffsplus = []
            if len(res - set(PERIODICITY)) > 0:
                diffs = sorted(res - set(PERIODICITY))
                difftxt = "with the exception of "
            if len(set(PERIODICITY) - res) > 0:
                # print("X")
                diffsplus = sorted(set(PERIODICITY) - res)
                diffplus = "plus on "
            for diff in diffs:
                datetemp = (datetime(2021, 1, 1) +
                            timedelta(int(diff) - 1)).strftime('%d/%m/%Y')
                exception += f"{datetemp}" if exception == "" else f", {datetemp}"
            for diff in diffsplus:
                datetemp = (datetime(2021, 1, 1) +
                            timedelta(int(diff) - 1)).strftime('%d/%m/%Y')
                exceptionplus += f"{datetemp}" if exceptionplus == "" else f", {datetemp}"
        if PERIODICITY.shape[0] != 0:
            exceptionplus = diffplus + exceptionplus if exceptionplus != "" else ""
            exception = difftxt + exception if exception != "" else ""
            preposition = "on" if msg[0] != 'f' else ""
            lbl = tkinter.Label(
                Top,
                text=
                f"The service is provided {preposition} {msg} from {startDate.strftime('%d/%m/%Y')} to {endDate.strftime('%d/%m/%Y')} {exceptionplus} {exception}",
                wraplength=300,
                justify="center").pack(padx=10, pady=10)
        else:
            lbl = tkinter.Label(
                Top,
                text=
                f"The service is not provided from {startDate.strftime('%d/%m/%Y')} to {endDate.strftime('%d/%m/%Y')}",
                wraplength=300,
                justify="center").pack(padx=10, pady=10)

        def restart():
            global Top, open, butText, randtxt, indexes, picked_ids, flagaRandom

            def clear():

                # for windows
                if os.name == 'nt':
                    _ = os.system('cls')

                    # for mac and linux(here, os.name is 'posix')
                else:
                    _ = os.system('clear')

            clear()
            flagaRandom = True
            butText = "Pick Date"
            randtxt = "Select random dates"
            indexes = []
            picked_ids = {
                "ids": [],
                "dates": [],
                "indexes": [],
            }
            Top.destroy()
            open()

        restart_button = tkinter.Button(Top,
                                        text="Restart program",
                                        command=restart).pack(padx=10, pady=10)

    pick_button = tkinter.Button(root, text=butText, command=grab_date)
    random_button = tkinter.Button(root,
                                   text=randtxt,
                                   command=random_events_button)
    end_button = tkinter.Button(root, text="Finish", command=stop_selecting)
    if switch:
        loop = root.after(100, date_check)
    else:
        print("[ERROR]")
        root.after_cancel(loop)
        loop = None
    my_label.pack(pady=10)
    pick_button.pack(pady=10)
    random_button.pack(pady=10)
    end_button.pack(padx=100)