-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (55 loc) · 2.21 KB
/
Copy pathmain.py
File metadata and controls
73 lines (55 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python3
import tkinter as tk
import csv
csv_file = "data.csv"
markdown_file = "data.md"
def create_markdown_table(csv_file):
with open(csv_file, newline="") as csvfile:
reader = csv.reader(csvfile)
table = "| " + " | ".join(next(reader)) + " |\n"
table += "| " + " | ".join(["---"] * len(next(reader))) + " |\n"
for row in reader:
table += "| " + " | ".join(row) + " |\n"
with open(markdown_file, "w") as mdfile:
mdfile.write(table)
def remove_newline(text):
return text.replace("\n", "")
def save_to_csv():
title = remove_newline(title_entry.get())
timeline = remove_newline(timeline_entry.get())
categories = remove_newline(categories_entry.get())
description = remove_newline(description_entry.get())
link = remove_newline(link_entry.get())
with open("data.csv", "a", newline="") as file:
writer = csv.writer(file)
writer.writerow([title, timeline, categories, description, link])
create_markdown_table(csv_file)
# Clear the entry fields after saving
title_entry.delete(0, tk.END)
timeline_entry.delete(0, tk.END)
categories_entry.delete(0, tk.END)
description_entry.delete(0, tk.END)
link_entry.delete(0, tk.END)
root = tk.Tk()
root.title("Data Entry Form")
# Labels
tk.Label(root, text="Title:").grid(row=0, column=0, padx=5, pady=5)
tk.Label(root, text="Timeline:").grid(row=1, column=0, padx=5, pady=5)
tk.Label(root, text="Categories:").grid(row=2, column=0, padx=5, pady=5)
tk.Label(root, text="Description:").grid(row=3, column=0, padx=5, pady=5)
tk.Label(root, text="Link:").grid(row=4, column=0, padx=5, pady=5)
# Entry fields
title_entry = tk.Entry(root)
title_entry.grid(row=0, column=1)
timeline_entry = tk.Entry(root)
timeline_entry.grid(row=1, column=1)
categories_entry = tk.Entry(root)
categories_entry.grid(row=2, column=1)
description_entry = tk.Entry(root)
description_entry.grid(row=3, column=1)
link_entry = tk.Entry(root)
link_entry.grid(row=4, column=1)
# Save button
save_button = tk.Button(root, text="Save", command=save_to_csv)
save_button.grid(row=5, column=0, columnspan=2, pady=10)
root.mainloop()