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