.exe files will only function on a PC
import tkinter as tk
from tkinter import ttk, messagebox, filedialog
from datetime import datetime
import csv
import os
CSV_FILE = "hive_inspections.csv"
# Load records from CSV
def load_records():
if not os.path.exists(CSV_FILE):
return []
with open(CSV_FILE, newline='', encoding="utf-8") as f:
reader = csv.reader(f)
return list(reader)[1:] # Skip header
# Save all records to CSV (overwrite)
def save_all_to_csv(records):
with open(CSV_FILE, "w", newline='', encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow(["Hive ID", "Location", "Date", "Notes"])
writer.writerows(records)
# Refresh Treeview
def refresh_tree():
tree.delete(*tree.get_children())
for i, row in enumerate(load_records()):
tree.insert("", "end", iid=str(i), values=row)
# Add Inspection
def add_record():
def save():
hive_id = hive_entry.get().strip()
location = location_entry.get().strip()
notes_text = notes_box.get("1.0", "end").strip()
if not hive_id:
messagebox.showwarning("Missing Data", "Hive ID is required.")
return
current_dt = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
new_record = [hive_id, location, current_dt, notes_text]
records = load_records()
records.insert(0, new_record)
save_all_to_csv(records)
popup.destroy()
refresh_tree()
popup = tk.Toplevel(root)
popup.title("Add Inspection")
tk.Label(popup, text="Hive ID").pack(pady=2)
hive_entry = tk.Entry(popup, width=30)
hive_entry.pack(pady=2)
tk.Label(popup, text="Location").pack(pady=2)
location_entry = tk.Entry(popup, width=30)
location_entry.pack(pady=2)
tk.Label(popup, text="Inspection Notes").pack(pady=2)
notes_box = tk.Text(popup, height=6, width=40, wrap="word")
notes_box.pack(pady=2)
tk.Button(popup, text="Save", command=save).pack(pady=5)
# View Details
def view_details():
selected = tree.focus()
if not selected:
messagebox.showinfo("No Selection", "Please select a record to view.")
return
hive_id, location, date, notes = tree.item(selected, "values")
detail_popup = tk.Toplevel(root)
detail_popup.title("Inspection Details")
tk.Label(detail_popup, text=f"Hive ID: {hive_id}").pack(pady=2)
tk.Label(detail_popup, text=f"Location: {location}").pack(pady=2)
tk.Label(detail_popup, text=f"Date: {date}").pack(pady=2)
tk.Label(detail_popup, text="Notes:").pack(pady=2)
notes_display = tk.Text(detail_popup, width=50, height=10, wrap="word")
notes_display.insert("1.0", notes)
notes_display.config(state="disabled")
notes_display.pack(pady=2)
# Edit Inspection
def edit_record():
selected = tree.focus()
if not selected:
messagebox.showinfo("No Selection", "Please select a record to edit.")
return
index = int(selected)
records = load_records()
current = records[index]
hive_id, location, date, notes = current
def save_edit():
new_hive = hive_entry.get().strip()
new_location = location_entry.get().strip()
new_notes = notes_box.get("1.0", "end").strip()
if not new_hive:
messagebox.showwarning("Missing Data", "Hive ID is required.")
return
records[index] = [new_hive, new_location, date, new_notes]
save_all_to_csv(records)
popup.destroy()
refresh_tree()
popup = tk.Toplevel(root)
popup.title("Edit Inspection")
tk.Label(popup, text="Hive ID").pack(pady=2)
hive_entry = tk.Entry(popup, width=30)
hive_entry.insert(0, hive_id)
hive_entry.pack(pady=2)
tk.Label(popup, text="Location").pack(pady=2)
location_entry = tk.Entry(popup, width=30)
location_entry.insert(0, location)
location_entry.pack(pady=2)
tk.Label(popup, text="Inspection Notes").pack(pady=2)
notes_box = tk.Text(popup, height=6, width=40, wrap="word")
notes_box.insert("1.0", notes)
notes_box.pack(pady=2)
tk.Button(popup, text="Save Changes", command=save_edit).pack(pady=5)
# Delete Inspection
def delete_record():
selected = tree.focus()
if not selected:
messagebox.showinfo("No Selection", "Please select a record to delete.")
return
confirm = messagebox.askyesno("Confirm Delete", "Are you sure you want to delete this inspection?")
if confirm:
index = int(selected)
records = load_records()
records.pop(index)
save_all_to_csv(records)
refresh_tree()
# Main App
root = tk.Tk()
root.title("Hive Inspection Records")
root.geometry("700x440")
tree = ttk.Treeview(root, columns=("Hive ID", "Location", "Date", "Notes"), show="headings")
tree.heading("Hive ID", text="Hive ID")
tree.heading("Location", text="Location")
tree.heading("Date", text="Date")
tree.heading("Notes", text="Notes")
tree.pack(fill="both", expand=True, padx=10, pady=10)
button_frame = tk.Frame(root)
button_frame.pack(pady=5)
tk.Button(button_frame, text="Add Inspection", command=add_record).pack(side="left", padx=5)
tk.Button(button_frame, text="View Details", command=view_details).pack(side="left", padx=5)
tk.Button(button_frame, text="Edit Inspection", command=edit_record).pack(side="left", padx=5)
tk.Button(button_frame, text="Delete Inspection", command=delete_record).pack(side="left", padx=5)
refresh_tree()
root.mainloop()
Copyright © 2025 schimanskibees.ca - All Rights Reserved.
We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data.