· 5 years ago · May 26, 2020, 06:54 AM
1import tkinter as tk
2from tkinter import ttk
3from tkinter import Label
4from tkinter import Entry
5from tkinter import Frame
6from tkinter import LabelFrame
7from tkinter import Spinbox
8
9from tkcalendar import Calendar, DateEntry
10from datetime import datetime
11from datetime import date
12
13import re
14import os
15import time
16
17import sqlite3
18
19global event_write
20event_write = []
21
22
23def example1():
24 def print_sel():
25 print(cal.selection_get())
26
27 top = tk.Toplevel(root)
28 top.title("Kalendarz")
29 cal = Calendar(top, font="Arial 14", selectmode='day', cursor="hand1")
30 cal.pack(fill="both", expand=True)
31 ttk.Button(top, text="Dodaj wydarzenie", command=event_add).pack()
32
33
34
35
36def update_current_datetime():
37 global current_datetime
38 current_datetime = datetime.now()
39 current_datetime = str(current_datetime.replace(second=0, microsecond=0))
40 notification()
41 root.after(60000, update_current_datetime)
42
43
44def notification():
45 print(current_datetime)
46 if len(event_write) >= 4:
47 end_datetime = event_write[2] + " " + event_write[3] + ":00"
48 if current_datetime == end_datetime:
49 root = tk.Tk()
50 Label(root, text="Nazwa wydarzenia: " + event_write[0]).pack()
51 Label(root, text="Treść: " + event_write[1]).pack()
52 for i in range(len(event_write)):
53 event_write.pop()
54
55
56# -------------------------------------------------- EVENTS CLASS --------------------------------------------------
57
58class Events():
59 def __init__(self):
60 self.top = events
61 self.top.grid_columnconfigure(0, weight=1)
62 self.top.buttonsframe = tk.Frame(self.top)
63 ttk.Button(self.top.buttonsframe, text="Dodaj wydarzenie", command=self.add_event_window).grid(row=0, column=0, padx=10, pady=5)
64 ttk.Button(self.top.buttonsframe, text="Modyfikuj wydarzenie", command=self.modify_event_window).grid(row=0, column=2, pady=5)
65 ttk.Button(self.top.buttonsframe, text="Usuń wydarzenie", command=self.delete_event_window).grid(row=0, column=3, pady=5)
66 self.top.buttonsframe.grid(row=0, column=0)
67 cols = ("ID", "Tytuł", "Data rozpoczęcia", "Data zakończenia", "Data przypomnienia", "Treść")
68 self.listBox = ttk.Treeview(self.top, columns=cols, show='headings', selectmode='browse')
69 for col in cols:
70 self.listBox.heading(col, text=col)
71
72 self.listBox.column("ID", stretch=False, width=40)
73 self.listBox.column("Tytuł", stretch=False, width=100)
74 self.listBox.column("Data rozpoczęcia", stretch=False, width=120)
75 self.listBox.column("Data zakończenia", stretch=False, width=120)
76 self.listBox.column("Data przypomnienia", stretch=False, width=120)
77 self.listBox.column("Treść", stretch=True, width=200)
78
79 self.listBox.grid(row=1, column=0, sticky="ew")
80
81 self.scrollhorizontal = tk.Scrollbar(self.top, orient="horizontal")
82 self.scrollhorizontal.grid(row=2, column=0, sticky="ew")
83 self.listBox.configure(xscrollcommand=self.scrollhorizontal.set)
84 self.scrollhorizontal.configure(command=self.listBox.xview)
85
86 self.scrollvertical = tk.Scrollbar(self.top, orient="vertical")
87 self.scrollvertical.grid(row=1, column=1, sticky="ns")
88 self.listBox.configure(yscrollcommand=self.scrollvertical.set)
89 self.scrollvertical.configure(command=self.listBox.yview)
90
91 self.read_all()
92
93 def read_all(self):
94 self.result_list = do_query("""SELECT id, title, date_start, date_end, date_reminder, content FROM Events;""")
95 self.listBox.delete(*self.listBox.get_children())
96 for i in self.result_list:
97 if len(i) != 0:
98 self.listBox.insert("", "end", values=(i[0], i[1], i[2], i[3], i[4], i[5].replace('\n', ' ').replace('\r', '')))
99 print(self.result_list)
100
101 def add_event(self, window, name, date_start, date_end, date_reminder, content):
102 if (not re.match(r"(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})", date_start) or
103 not re.match(r"(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})", date_end) or
104 not re.match(r"(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})", date_reminder)):
105 error = tk.Toplevel(self.top)
106 error.title("Błąd")
107 Label(error, text="Nieprawidłowa data").grid(padx=25)
108 ttk.Button(error, text='OK', command=error.destroy).grid(padx=10, pady=10)
109 root.update_idletasks()
110 error.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - error.winfo_width() / 2, root.winfo_screenheight() / 2 - error.winfo_height() / 2))
111 error.focus_set()
112 error.grab_set()
113
114 else:
115 do_query("""INSERT INTO Events (title, date_start, date_end, date_reminder, content) VALUES ('{}', '{}', '{}', '{}', '{}')""".format(name, date_start, date_end, date_reminder, content))
116 self.read_all()
117 window.destroy()
118 return
119
120 def add_event_window(self): #TODO DATE_END POZNIEJ NIZ DATE_START, DATE REMINDER PRZED DATE_END
121 add = tk.Toplevel(root)
122 add.resizable(0, 0)
123 add.title("Nowe wydarzenie")
124 add.nameframe = tk.Frame(add)
125 add.label = tk.Label(add.nameframe, text="Nazwa:")
126 add.label.grid(row=0, column=0)
127 add.name = tk.Entry(add.nameframe, width=70, font=("Calibri"))
128 add.name.grid(row=0, column=1)
129 add.nameframe.grid(row=0, column=0, columnspan=3)
130 add.date_start_label = tk.Label(add, text="Rozpoczęcie:")
131 add.date_start = tk.Entry(add, font=("Calibri"))
132 add.date_start.bind("<1>", lambda x: calendar_input(self.top, add.date_start))
133 add.date_end_label = tk.Label(add, text="Zakończenie:")
134 add.date_end = tk.Entry(add, font=("Calibri"))
135 add.date_end.bind("<1>", lambda x: calendar_input(self.top, add.date_end))
136 add.date_reminder_label = tk.Label(add, text="Przypomnienie:")
137 add.date_reminder = tk.Entry(add, font=("Calibri"))
138 add.date_reminder.bind("<1>", lambda x: calendar_input(self.top, add.date_reminder))
139 add.date_start_label.grid(row=1, column=0)
140 add.date_start.grid(row=2, column=0, sticky="we", padx=6)
141 add.date_end_label.grid(row=1, column=1)
142 add.date_end.grid(row=2, column=1, sticky="we", padx=6)
143 add.date_reminder_label.grid(row=1, column=2)
144 add.date_reminder.grid(row=2, column=2, sticky="we", padx=6)
145 add.content = tk.Text(add, width=80, height=15, font=("Calibri"))
146 add.content.grid(row=3, column=0, columnspan=3, padx=6, pady=6)
147 ttk.Button(add, text='OK', command=lambda: self.add_event(add, add.name.get(), add.date_start.get(), add.date_end.get(), add.date_reminder.get(), add.content.get(1.0, "end"))).grid(row=4, column=2, pady=10, padx=10, sticky="we")
148 ttk.Button(add, text='ANULUJ', command=add.destroy).grid(row=4, column=0, pady=10, padx=10, sticky="we")
149 root.update_idletasks()
150 add.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - add.winfo_width() / 2, root.winfo_screenheight() / 2 - add.winfo_height() / 2))
151 add.focus_set()
152 add.grab_set()
153 return
154
155 def modify_event(self, window, id, name, date_start, date_end, date_reminder, content):
156 do_query("""UPDATE Events SET title = '{}', date_start = '{}' ,date_end = '{}' ,date_reminder = '{}' ,content = '{}' WHERE id='{}' """.format(name, date_start, date_end, date_reminder, content, id))
157 self.read_all()
158 window.destroy()
159 return
160
161 def modify_event_window(self): # TODO STRIP NEWLINES IN TEXT BOX
162 if len(self.listBox.item(self.listBox.focus())["values"]) != 6:
163 error = tk.Toplevel(self.top)
164 error.title("Błąd")
165 Label(error, text="Najpierw wybierz wydarzenie!").grid(padx=25)
166 ttk.Button(error, text='OK', command=error.destroy).grid(padx=10, pady=10)
167 root.update_idletasks()
168 error.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - error.winfo_width() / 2, root.winfo_screenheight() / 2 - error.winfo_height() / 2))
169 error.focus_set()
170 error.grab_set()
171 else:
172 id_from_list = self.listBox.item(self.listBox.focus())["values"][0]
173 [id, title, date_start, date_end, date_reminder, content] = next(row for row in self.result_list if id_from_list in row)
174 modify = tk.Toplevel(root)
175 modify.resizable(0, 0)
176 modify.title("Modyfikuj wydarzenie")
177 modify.nameframe = tk.Frame(modify)
178 modify.label = tk.Label(modify.nameframe, text="Nazwa:")
179 modify.label.grid(row=0, column=0)
180 modify.name = tk.Entry(modify.nameframe, width=70, font=("Calibri"))
181 modify.name.insert(0, title)
182 modify.name.grid(row=0, column=1)
183 modify.nameframe.grid(row=0, column=0, columnspan=3)
184 modify.date_start_label = tk.Label(modify, text="Rozpoczęcie:")
185 modify.date_start = tk.Entry(modify, font=("Calibri"))
186 modify.date_start.insert(0, date_start)
187 modify.date_start.bind("<1>", lambda x: calendar_input(self.top, modify.date_start))
188 modify.date_end_label = tk.Label(modify, text="Zakończenie:")
189 modify.date_end = tk.Entry(modify, font=("Calibri"))
190 modify.date_end.insert(0, date_end)
191 modify.date_end.bind("<1>", lambda x: calendar_input(self.top, modify.date_end))
192 modify.date_reminder_label = tk.Label(modify, text="Przypomnienie:")
193 modify.date_reminder = tk.Entry(modify, font=("Calibri"))
194 modify.date_reminder.insert(0, date_reminder)
195 modify.date_reminder.bind("<1>", lambda x: calendar_input(self.top, modify.date_reminder))
196 modify.date_start_label.grid(row=1, column=0)
197 modify.date_start.grid(row=2, column=0, sticky="we", padx=6)
198 modify.date_end_label.grid(row=1, column=1)
199 modify.date_end.grid(row=2, column=1, sticky="we", padx=6)
200 modify.date_reminder_label.grid(row=1, column=2)
201 modify.date_reminder.grid(row=2, column=2, sticky="we", padx=6)
202 modify.content = tk.Text(modify, width=80, height=15, font=("Calibri"))
203 modify.content.insert(1.0, content)
204 modify.content.grid(row=3, column=0, columnspan=3, padx=6, pady=6)
205 ttk.Button(modify, text='OK', command=lambda: self.modify_event(modify, id, modify.name.get(), modify.date_start.get(), modify.date_end.get(), modify.date_reminder.get(), modify.content.get(1.0, "end"))).grid(row=4, column=2, pady=10, padx=10, sticky="we")
206 ttk.Button(modify, text='ANULUJ', command=modify.destroy).grid(row=4, column=0, pady=10, padx=10, sticky="we")
207 root.update_idletasks()
208 modify.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - modify.winfo_width() / 2, root.winfo_screenheight() / 2 - modify.winfo_height() / 2))
209 modify.focus_set()
210 modify.grab_set()
211 return
212
213 def delete_event(self, window, id):
214 do_query("""DELETE FROM Events WHERE id='{}' """.format(id))
215 self.read_all()
216 window.destroy()
217 return
218
219 def delete_event_window(self): #TODO EVENT DELETE
220 if len(self.listBox.item(self.listBox.focus())["values"]) != 6:
221 error = tk.Toplevel(self.top)
222 error.title("Błąd")
223 Label(error, text="Najpierw wybierz wydarzenie!").grid(padx=25)
224 ttk.Button(error, text='OK', command=error.destroy).grid(padx=10, pady=10)
225 root.update_idletasks()
226 error.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - error.winfo_width() / 2, root.winfo_screenheight() / 2 - error.winfo_height() / 2))
227 error.focus_set()
228 error.grab_set()
229 else:
230 id = self.listBox.item(self.listBox.focus())["values"][0]
231 delete = tk.Toplevel(root)
232 delete.resizable(0, 0)
233 delete.title("Potwierdź usuwanie")
234 delete.label = tk.Label(delete, text="Czy na pewno chcesz usunąć to wydarzenie?")
235 delete.label.grid(row=0, column=0, columnspan=2)
236 ttk.Button(delete, text='TAK', command=lambda: self.delete_event(delete, id)).grid(row=1, column=1, pady=10)
237 ttk.Button(delete, text='NIE', command=delete.destroy).grid(row=1, column=0, pady=10)
238 root.update_idletasks()
239 delete.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - delete.winfo_width() / 2, root.winfo_screenheight() / 2 - delete.winfo_height() / 2))
240 delete.focus_set()
241 delete.grab_set()
242 return
243
244
245# -------------------------------------------------- TODOS CLASS ---------------------------------------------------
246
247# -------------------------------------------------- NOTES CLASS ---------------------------------------------------
248
249class Notes():
250 def __init__(self):
251 self.top = notes
252 self.top.grid_columnconfigure(0, weight=1)
253 self.top.buttonsframe = tk.Frame(self.top)
254 ttk.Button(self.top.buttonsframe, text='Dodaj notatkę', command=self.add_note_window).grid(row=0, column=0, padx=10, pady=5)
255 ttk.Button(self.top.buttonsframe, text='Modyfikuj notatkę', command=self.modify_note_window).grid(row=0, column=2, padx=10, pady=5)
256 ttk.Button(self.top.buttonsframe, text='Usuń notatkę', command=self.delete_note_window).grid(row=0, column=3, padx=10, pady=5)
257 self.top.buttonsframe.grid(row=0, column=0)
258 cols = ('ID', 'Tytuł', 'Treść')
259 self.listBox = ttk.Treeview(self.top, columns=cols, show='headings', selectmode='browse')
260 for col in cols:
261 self.listBox.heading(col, text=col) # TODO anchor="w"
262
263 self.listBox.column("ID", stretch=False, width=40)
264 self.listBox.column("Tytuł", stretch=False, width=100)
265 self.listBox.column("Treść", stretch=True, minwidth=200)
266
267 self.listBox.grid(row=1, column=0, sticky="ew")
268
269 self.scrollhorizontal = tk.Scrollbar(self.top, orient="horizontal")
270 self.scrollhorizontal.grid(row=2, column=0, sticky="ew")
271 self.listBox.configure(xscrollcommand=self.scrollhorizontal.set)
272 self.scrollhorizontal.configure(command=self.listBox.xview)
273
274 self.scrollvertical = tk.Scrollbar(self.top, orient="vertical")
275 self.scrollvertical.grid(row=1, column=1, sticky="ns")
276 self.listBox.configure(yscrollcommand=self.scrollvertical.set)
277 self.scrollvertical.configure(command=self.listBox.yview)
278
279 self.read_all()
280
281 def read_all(self):
282 self.result_list = do_query("""SELECT * FROM Notes;""")
283 self.listBox.delete(*self.listBox.get_children())
284 for i in self.result_list:
285 if len(i) != 0:
286 self.listBox.insert("", "end", values=(i[0], i[1], i[2].replace('\n', ' ').replace('\r', '')))
287
288 #next(row for row in self.result_list if 2 in row))
289
290 def add_note(self, window, name, content):
291 do_query("""INSERT INTO Notes (title, content) VALUES ('{}', '{}')""".format(name, content))
292 self.read_all()
293 window.destroy()
294 return
295
296 def add_note_window(self):
297 add = tk.Toplevel(root)
298 add.resizable(0, 0)
299 add.title("Nowa notatka")
300 add.nameframe = tk.Frame(add)
301 add.label = tk.Label(add.nameframe, text="Nazwa:")
302 add.label.grid(row=0, column=0)
303 add.name = tk.Entry(add.nameframe, width=70, font=("Calibri"))
304 add.name.grid(row=0, column=1)
305 add.nameframe.grid(row=0, column=0, columnspan=3)
306 add.content = tk.Text(add, width=80, height=15, font=("Calibri"))
307 add.content.grid(row=1, column=0, columnspan=3, padx=6, pady=6)
308 ttk.Button(add, text='OK', command=lambda: self.add_note(add, add.name.get(), add.content.get(1.0, "end"))).grid(row=2, column=2, pady=10, padx=10, sticky="we")
309 ttk.Button(add, text='ANULUJ', command=add.destroy).grid(row=2, column=0, pady=10, padx=10, sticky="we")
310 root.update_idletasks()
311 add.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - add.winfo_width() / 2, root.winfo_screenheight() / 2 - add.winfo_height() / 2))
312 add.focus_set()
313 add.grab_set()
314 return
315
316 def modify_note(self, window, id, name, content):
317 do_query("""UPDATE Notes SET title = '{}', content = '{}' WHERE id='{}' """.format(name, content, id))
318 self.read_all()
319 window.destroy()
320 return
321
322 def modify_note_window(self): # TODO STRIP NEWLINES IN TEXT BOX
323 if len(self.listBox.item(self.listBox.focus())["values"]) != 3:
324 error = tk.Toplevel(self.top)
325 error.title("Błąd")
326 Label(error, text="Najpierw wybierz notatkę!").grid(padx=25)
327 ttk.Button(error, text='OK', command=error.destroy).grid(padx=10, pady=10)
328 root.update_idletasks()
329 error.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - error.winfo_width() / 2, root.winfo_screenheight() / 2 - error.winfo_height() / 2))
330 error.focus_set()
331 error.grab_set()
332 else:
333 id_from_list = self.listBox.item(self.listBox.focus())["values"][0]
334 [id, title, content] = next(row for row in self.result_list if id_from_list in row)
335 modify = tk.Toplevel(root)
336 modify.resizable(0, 0)
337 modify.title("Modifykacja notatki")
338 modify.nameframe = tk.Frame(modify)
339 modify.label = tk.Label(modify.nameframe, text="Nazwa:")
340 modify.label.grid(row=0, column=0)
341 modify.name = tk.Entry(modify.nameframe, width=70, font=("Calibri"))
342 modify.name.insert(0, title)
343 modify.name.grid(row=0, column=1)
344 modify.nameframe.grid(row=0, column=0, columnspan=3)
345 modify.content = tk.Text(modify, width=80, height=15, font=("Calibri"))
346 modify.content.insert(1.0, content)
347 modify.content.grid(row=1, column=0, columnspan=3, padx=6, pady=6)
348 ttk.Button(modify, text='OK', command=lambda: self.modify_note(modify, id, modify.name.get(), modify.content.get(1.0, "end"))).grid(row=2, column=2, pady=10, padx=10, sticky="we")
349 ttk.Button(modify, text='ANULUJ', command=modify.destroy).grid(row=2, column=0, pady=10, padx=10, sticky="we")
350 root.update_idletasks()
351 modify.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - modify.winfo_width() / 2, root.winfo_screenheight() / 2 - modify.winfo_height() / 2))
352 modify.focus_set()
353 modify.grab_set()
354 return
355
356 def delete_note(self, window, id):
357 do_query("""DELETE FROM Notes WHERE id='{}' """.format(id))
358 self.read_all()
359 window.destroy()
360 return
361
362 def delete_note_window(self):
363 if len(self.listBox.item(self.listBox.focus())["values"]) != 3:
364 error = tk.Toplevel(self.top)
365 error.title("Błąd")
366 Label(error, text="Najpierw wybierz notatkę!").grid(padx=25)
367 ttk.Button(error, text='OK', command=error.destroy).grid(padx=10, pady=10)
368 root.update_idletasks()
369 error.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - error.winfo_width() / 2, root.winfo_screenheight() / 2 - error.winfo_height() / 2))
370 error.focus_set()
371 error.grab_set()
372 else:
373 id = self.listBox.item(self.listBox.focus())["values"][0]
374 delete = tk.Toplevel(root)
375 delete.resizable(0, 0)
376 delete.title("Potwierdź usuwanie")
377 delete.label = tk.Label(delete, text="Czy na pewno chcesz usunąć tą notatkę?")
378 delete.label.grid(row=0, column=0, columnspan=2)
379 ttk.Button(delete, text='TAK', command=lambda: self.delete_note(delete, id)).grid(row=1, column=1, pady=10)
380 ttk.Button(delete, text='NIE', command=delete.destroy).grid(row=1, column=0, pady=10)
381 root.update_idletasks()
382 delete.geometry("+%d+%d" % (root.winfo_screenwidth() / 2 - delete.winfo_width() / 2, root.winfo_screenheight() / 2 - delete.winfo_height() / 2))
383 delete.focus_set()
384 delete.grab_set()
385 return
386
387
388# ---------------------------------------- VIEW DATE RANGE CHANGER -------------------------------------------------
389
390class Range_changer():
391 def __init__(self):
392 self.top = changer
393 self.top.grid_columnconfigure(0, weight=1)
394 self.labelframe = LabelFrame(self.top, text="Zakres dat")
395 self.date_from_label = tk.Label(self.labelframe, text="od:")
396 self.date_from_label.grid(row=0, column=1, padx=(10,0))
397 self.date_from = tk.Entry(self.labelframe, font=("Calibri"))
398 self.date_from.grid(row=0, column=2, padx=(2,10))
399 self.date_to_label = tk.Label(self.labelframe, text="do:")
400 self.date_to_label.grid(row=0, column=3, padx=(10,0))
401 self.date_to = tk.Entry(self.labelframe, font=("Calibri"))
402 self.date_to.grid(row=0, column=4, padx=(2,10))
403 self.change_button = ttk.Button(self.labelframe, text="Zastosuj", command=self.change_range).grid(row=0, column=5, padx=10, pady=10)
404 self.reset_button = ttk.Button(self.labelframe, text="Resetuj", command=self.reset_range).grid(row=0, column=6, padx=10, pady=10)
405
406 self.labelframe.grid(sticky="ew")
407
408 self.date_from.bind("<1>", lambda x: calendar_input(self.top, self.date_from))
409 self.date_to.bind("<1>", lambda x: calendar_input(self.top, self.date_to))
410
411
412 def change_range(self):
413 return
414
415 def reset_range(self):
416 return
417
418
419# --------------------------------------------- CALENDAR ----------------------------------------------------
420
421
422def calendar_input(parent, widget):
423 previous_value = widget.get()
424 new_value = calendar_window(parent, previous_value)
425 widget.delete(0, "end")
426 widget.insert(0, new_value)
427
428def calendar_window(parent, date_time):
429
430 result = None
431 cal_window = tk.Toplevel(parent)
432 cal_window.title("Data i godzina")
433 cal_window.attributes("-topmost", True)
434 cal_window.resizable(False, False)
435 root.update_idletasks()
436 cal_window.geometry("+%d+%d" % (parent.winfo_screenwidth() / 2 - cal_window.winfo_width() / 2, root.winfo_screenheight() / 2 - cal_window.winfo_height() / 2))
437
438 def command():
439 nonlocal result
440 result = str(cal.selection_get()) + " " + pick_h.get()+":"+ pick_min.get()
441 cal_window.quit()
442 cal_window.destroy()
443
444 cal_window.protocol("WM_DELETE_WINDOW", command)
445
446 time = tk.Entry(cal_window, width=8, font=("Calibri"))
447
448 if re.match(r"(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})", date_time):
449 values = datetime.strptime(date_time, '%Y-%m-%d %H:%M:%S')
450 cal = Calendar(cal_window, selectmode='day', year=values.year, month=values.month, day=values.day)
451 time.insert(0,values.strftime('%H:%M:%S'))
452 else:
453 cal = Calendar(cal_window, selectmode='day')
454 time.insert(0, '12:00:00')
455
456#clock time format validation functions:
457 def callback(input):
458 if input.isdigit() and 0<= int(input) <= 23:
459 return True
460 elif input is "":
461 return True
462 else:
463 return False
464
465 def callback2(input):
466 if input.isdigit() and 0<= int(input) <=59:
467 return True
468 elif input is "":
469 return True
470 else:
471 return False
472
473
474#clock spinboxes:
475 reg=root.register(callback)
476 pick_h = Spinbox(cal_window,from_=00, to=23, width=2, font='Calibri',
477 wrap=True,validate="key",
478 validatecommand=(reg, '%P'),
479 invalidcommand=lambda: print("Wprowadź godz od 0 do 23"))
480
481 reg2=root.register(callback2)
482 pick_min = Spinbox(cal_window,from_=00, to=59, width=2, font='Calibri',
483 wrap=True,validate="key",
484 validatecommand=(reg2, '%P'),
485 invalidcommand=lambda: print("Wprowadź min od 00 do 59"))
486
487 lbl3 = Label(cal_window, text="Wprowadż godzinę wydarzenia: ", width=6, justify="left")
488 ttk.Button(cal_window, text="OK", command=command).pack(side="bottom")
489
490#calendar widget position:
491 cal.pack(side="top",fill="both",expand=True)
492 lbl3.pack(side="left",fill="x",expand=True)
493 pick_h.pack(side="left")
494 pick_min.pack(side="right")
495
496 cal_window.focus_set()
497 cal_window.grab_set()
498 cal_window.mainloop()
499 return result
500
501
502
503# -------------------------------------------------- SQLITE ---------------------------------------------------
504
505
506def do_query(query):
507 conn = sqlite3.connect('organizer.db')
508 cur = conn.cursor()
509 cur.execute(query)
510 conn.commit()
511 return list(cur.fetchall())
512
513
514def init_sqlite(filename):
515 conn = sqlite3.connect(filename)
516 cur = conn.cursor()
517 if not os.path.exists(filename):
518 print('Creating database')
519 cur.execute("""
520 CREATE TABLE IF NOT EXISTS notes (
521 id INTEGER PRIMARY KEY AUTOINCREMENT,
522 title TEXT NOT NULL,
523 content TEXT
524 )
525 """
526 )
527 conn.commit()
528 cur.execute("""
529 CREATE TABLE IF NOT EXISTS events (
530 id INTEGER PRIMARY KEY AUTOINCREMENT,
531 title TEXT NOT NULL,
532 content TEXT,
533 date_start DATETIME,
534 date_end DATETIME,
535 date_reminder DATETIME
536 )
537 """
538 )
539 conn.commit()
540 conn.close()
541
542
543# -------------------------------------------------- MAIN ---------------------------------------------------
544# grid_columnconfigure(0, weight=1)
545
546
547#print(calendar_window())
548
549range_from = None
550range_to = None
551
552init_sqlite('organizer.db')
553root = tk.Tk()
554root.title("Organizator")
555root.geometry("1000x800")
556root.resizable(1, 1);
557root.grid_columnconfigure(0, weight=1)
558root.grid()
559s = ttk.Style(root)
560s.theme_use('clam')
561update_current_datetime()
562notes = Frame(root)
563changer = Frame(root)
564events = Frame(root)
565todos = Frame(root)
566# notes.configure(background="black")
567notes.grid(row=0, column=0, sticky="we")
568changer.grid(row=1, column=0, sticky="we")
569events.grid(row=2, column=0, sticky="we")
570todos.grid(row=3, column=0, sticky="we")
571notes_widget = Notes()
572changer_widget = Range_changer()
573events_widget = Events()
574# Todos()
575
576root.mainloop()