import sqlite3 from datetime import datetime import time import tkinter as tk con = sqlite3.connect("todo.db") cur = con.cursor() def get_time(): return (datetime.now() - datetime(1970, 1, 1)).total_seconds() + time.timezone # timezone so we get utc time! def add_item_dialog(): input_field = tk.Tk() input_field.title("Add Item") input_window_width = 640 input_window_height = 320 # find the center point input_center_x = int(screen_width / 2 - input_window_width / 2) input_center_y = int(screen_height / 2 - input_window_height / 2) input_field.geometry(f'{input_window_width}x{input_window_height}+{input_center_x}+{input_center_y}') # Create an entry for adding items entry = tk.Entry(input_field, width=50) entry.pack(padx=10, pady=5) input_confirm = tk.Button(input_field, text="Confirm", command=lambda: add_item(entry, input_field)) input_confirm.pack(side=tk.BOTTOM, padx=5, pady=5) input_field.mainloop() def add_item(entry, input_field): item = entry.get() print("a") if item: listbox.insert(tk.END, item) cur.execute("INSERT INTO todo(\"ID\",\"TODO\",\"CREATION_DATE\",\"DUE_DATE\",\"PRIO\",\"IMP\") VALUES (NULL, " "'%s', '%s','%s', '%s', '%s' )" % (item, get_time(), get_time(), 100, 0)) con.commit() input_field.destroy() def remove_item(): selected_index = listbox.curselection() if selected_index: listbox.delete(selected_index) def update_list(): listbox.delete(0, listbox.size()) # clear listbox cur_time = get_time() total_time = [] remaining_time = [] importance = [] res = cur.execute("SELECT * FROM todo").fetchall() for i, tmp1 in enumerate(res): total_time.append(res[i][3] - res[i][2]) remaining_time.append(res[i][3] - cur_time) importance.append(total_time[i] / remaining_time[i] * res[i][4]) if int(importance[i]) == 0: importance[i] = 1 print("UPDATE todo SET IMP = %s WHERE ID = %s" % (int(importance[i]), i + 1)) cur.execute("UPDATE todo SET IMP = %s WHERE ID = %s" % (int(importance[i]), i + 1)) print(i) listbox.insert(tk.END, res[i][1]) con.commit() # Create the main window root = tk.Tk() root.title("Ion-Todo-Planner") # get the screen dimension screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() window_width = 1280 window_height = 720 # find the center point center_x = int(screen_width / 2 - window_width / 2) center_y = int(screen_height / 2 - window_height / 2) # set the position of the window to the center of the screen root.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}') root.minsize(window_width, window_height) # prevent making it smaller than min size # Create a listbox to display the items listbox = tk.Listbox(root, width=100) listbox.pack(padx=5, pady=5) # Create buttons to add and remove items add_button = tk.Button(root, text="Add", command=add_item_dialog) add_button.pack(side=tk.LEFT, padx=5, pady=5) remove_button = tk.Button(root, text="Remove", command=remove_item) remove_button.pack(side=tk.LEFT, padx=5, pady=5) update_button = tk.Button(root, text="Update", command=update_list) update_button.pack(side=tk.LEFT, padx=5, pady=5) # Run the Tkinter event loop root.mainloop()