This commit is contained in:
Nathan 2025-12-15 09:16:19 +07:00
commit 17bdf516b3

View File

@ -5,6 +5,8 @@ import sqlite3
import datetime import datetime
import os import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# ================= DATABASE CONNECT ================= # ================= DATABASE CONNECT =================
def connect(): def connect():
return sqlite3.connect("cafe.db") return sqlite3.connect("cafe.db")
@ -124,17 +126,26 @@ class PembeliMenu:
card.grid_propagate(False) card.grid_propagate(False)
try: try:
filename = os.path.basename(gambar) if gambar else None if not gambar:
img_path = os.path.join("aset", filename) if filename else None raise ValueError("gambar kosong")
if img_path and os.path.exists(img_path):
img = Image.open(img_path).resize((140, 90)) # gambar dari DB sudah mengandung 'aset/...'
photo = ImageTk.PhotoImage(img) img_path = os.path.join(BASE_DIR, gambar)
self.images.append(photo)
tk.Label(card, image=photo).pack(pady=5) if not os.path.exists(img_path):
else: raise FileNotFoundError(img_path)
tk.Label(card, text="[No Image]", height=6).pack()
except Exception: img = Image.open(img_path)
tk.Label(card, text="Error Img", height=6).pack() img = img.resize((140, 90), Image.Resampling.LANCZOS)
photo = ImageTk.PhotoImage(img)
self.images.append(photo)
tk.Label(card, image=photo).pack(pady=5)
except Exception as e:
print("IMG ERROR:", e)
tk.Label(card, text="No Image", height=6).pack()
tk.Label(card, text=nama, font=("Arial", 10, "bold"), wraplength=160).pack() tk.Label(card, text=nama, font=("Arial", 10, "bold"), wraplength=160).pack()
tk.Label(card, text=f"Rp {harga:,.0f}").pack(pady=2) tk.Label(card, text=f"Rp {harga:,.0f}").pack(pady=2)