BloomCode & Cropper
Hey BloomCode, I’ve been tinkering with the old seed trays lately and noticed how fast the seedlings grow in that shade of blue you paint on your screens. Got any code that could help us map out the best spots for each crop, or maybe a little app to keep track of soil moisture?
Hey! I’ve written a little Python script that draws a simple grid of your trays, lets you click on a spot and tag it with the crop you’re growing. It also logs a moisture reading you can type in later. Just paste it into a file, install tkinter with `pip install tk` if you need it, and run it.
```python
import tkinter as tk
from datetime import datetime
# Configuration
ROWS, COLS = 4, 6 # size of your tray grid
CELL_SIZE = 80 # pixels
MOISTURE_LOG = "soil_moisture.txt"
# Main window
root = tk.Tk()
root.title("Seed Tray Planner")
# Canvas for grid
canvas = tk.Canvas(root, width=COLS*CELL_SIZE, height=ROWS*CELL_SIZE)
canvas.pack()
# Data structures
spots = {} # (row,col): {"crop": str, "moisture": float, "time": datetime}
def save_moisture(row, col, moisture):
entry = spots.setdefault((row, col), {})
entry["moisture"] = moisture
entry["time"] = datetime.now()
with open(MOISTURE_LOG, "a") as f:
f.write(f"{entry['time']}, {row},{col}, {moisture}\n")
def on_click(event):
col = event.x // CELL_SIZE
row = event.y // CELL_SIZE
crop = tk.simpledialog.askstring("Crop", "Enter crop name:")
if crop:
spots[(row, col)] = {"crop": crop}
canvas.itemconfig(spots[(row, col)]["rect"], fill="lightgreen")
canvas.itemconfig(spots[(row, col)]["label"], text=crop)
# ask for moisture right away
m = tk.simpledialog.askfloat("Moisture", "Moisture level (0-100):")
if m is not None:
save_moisture(row, col, m)
# Draw grid cells
for r in range(ROWS):
for c in range(COLS):
x1, y1 = c*CELL_SIZE, r*CELL_SIZE
x2, y2 = x1+CELL_SIZE, y1+CELL_SIZE
rect = canvas.create_rectangle(x1, y1, x2, y2, fill="lightblue")
label = canvas.create_text(x1+CELL_SIZE/2, y1+CELL_SIZE/2,
text=f"{r},{c}", font=("Arial", 12))
spots[(r, c)] = {"rect": rect, "label": label}
canvas.bind("<Button-1>", on_click)
root.mainloop()
```
It’s very basic but gives you a visual map and a quick way to jot down moisture. Feel free to tweak the colors or add more fields like sunlight or fertilizer. Happy growing!
Looks good enough for a quick layout. Maybe keep the grid a bit bigger if you have a lot of trays, and you could log the time you watered instead of just the moisture. That way you can see when each spot needs a refill. Happy planting!