This repository has been archived on 2025-03-13. You can view files and clone it, but cannot push or open issues or pull requests.
Ion-Todo-Planner/main.py
2024-03-26 00:07:22 +01:00

68 lines
1.8 KiB
Python

import sqlite3
from datetime import datetime
import time
import tkinter as tk
con = sqlite3.connect("todo.db")
cur = con.cursor()
def add_item():
item = entry.get()
if item:
listbox.insert(tk.END, item)
entry.delete(0, tk.END) # deletes input
def remove_item():
selected_index = listbox.curselection()
if selected_index:
listbox.delete(selected_index)
def update_list():
cur_time = (datetime.now() - datetime(1970, 1, 1)).total_seconds() + time.timezone
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][0])
con.commit()
# Create the main window
root = tk.Tk()
root.title("Ion-Todo-Planner")
# Create a listbox to display the items
listbox = tk.Listbox(root, width=100)
listbox.pack(padx=5, pady=5)
# Create an entry for adding items
entry = tk.Entry(root, width=50)
entry.pack(padx=10, pady=5)
# Create buttons to add and remove items
add_button = tk.Button(root, text="Add", command=add_item)
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(padx=5, pady=5)
# Run the Tkinter event loop
root.mainloop()