Search

QR μ½”λ“œ 생성 ν”„λ‘œκ·Έλž¨

ν”„λ‘œκ·Έλž¨ 이름

μ„€λͺ…

ν”„λ‘œκ·Έλž¨

1
2

ν”„λ‘¬ν”„νŠΈ

페λ₯΄μ†Œλ‚˜ - 파이썬 ν”„λ‘œκ·Έλž˜λ° ν•™μŠ΅μž μž‘μ—… - QR μ½”λ“œ 생성 ν”„λ‘œκ·Έλž¨ 개발 λ§₯락 - μ–Έμ–΄ : 파이썬 - 버전 : 3.13 - ꡬ쑰 : GUI ν”„λ‘œκ·Έλž¨ - κΈ°λŠ₯ * QR μ½”λ“œ 생성 * QR κ΄€λ ¨ 정보 μž…λ ₯ : QRμ½”λ“œ 이름, QR μ½”λ“œ κ°’, 파일경둜 * MySQL λ°μ΄ν„°λ² μ΄μŠ€λ‘œ QRμ½”λ“œ 정보 관리 * QR μ½”λ“œ 관리 : QRμ½”λ“œ 이름 λ³€κ²½, QRμ½”λ“œ 정보 및 이미지 μ‚­μ œ * QR μ½”λ“œ 관리 λŒ€μ‹œλ³΄λ“œ : λ“±λ‘λœ QR μ½”λ“œ 리슀트둜 확인, μˆ˜μ • μ‚­μ œ μ•„μ΄μ½˜ λ²„νŠΌμœΌλ‘œ 관리 * QR μ½”λ“œ μˆ˜μ • ν™”λ©΄ : μ½”λ“œ 이름 λ³€κ²½, μ‚­μ œ λ²„νŠΌ * DB 접속 μ‹œ qr_code ν…Œμ΄λΈ” 생성 ν˜•μ‹ - QRμ½”λ“œ 이미지 ν™•μž₯자 : png - 이미지 파일 이름 : 연월일_μ‹œλΆ„μ΄ˆ_μ½”λ“œμ΄λ¦„.png - QR μ½”λ“œ 정보 ν…Œμ΄λΈ” : qr_code (no, id, name, value, path, created_at, updated_at) (번호, UUID, QRμ½”λ“œμ΄λ¦„, μ½”λ“œ κ°’, 파일경둜, λ“±λ‘μΌμž, μˆ˜μ •μΌμž) - db 접속 정보 * 계정 : python * λΉ„λ°€λ²ˆν˜Έ : 123456 * λ°μ΄ν„°λ² μ΄μŠ€ : python μ˜ˆμ‹œ - "https://xn--pe5b27r.com/" λ₯Ό μ½”λ“œ κ°’μœΌλ‘œ μ§€μ •ν•˜κ³  μ•Œν΄ μ‚¬μ΄νŠΈ λΌλŠ” qrμ½”λ“œ μ΄λ¦„μœΌλ‘œ c:/qrcode/파일λͺ… 경둜둜 μ €μž₯ μΊ”λ²„μŠ€ λͺ¨λ“œλ‘œ 응닡
Plain Text
볡사

μ„€μΉ˜

pip install qrcode[pil] pillow mysql-connector-python
Bash
볡사

DB ꡬ좕

-- 1. μ‚¬μš©μž 계정 생성 (λΉ„λ°€λ²ˆν˜ΈλŠ” '123456') CREATE USER 'python'@'localhost' IDENTIFIED BY '123456'; -- 2. λ°μ΄ν„°λ² μ΄μŠ€κ°€ μ—†λ‹€λ©΄ 생성 CREATE DATABASE IF NOT EXISTS python DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -- 3. κΆŒν•œ λΆ€μ—¬ (qr_db 에 λŒ€ν•œ λͺ¨λ“  κΆŒν•œ) GRANT ALL PRIVILEGES ON python.* TO 'python'@'localhost'; -- 4. 변경사항 적용 FLUSH PRIVILEGES;
SQL
볡사
CREATE TABLE qr_code ( no INT AUTO_INCREMENT PRIMARY KEY, id CHAR(36) NOT NULL UNIQUE, -- UUID name VARCHAR(100) NOT NULL, -- QR μ½”λ“œ 이름 value TEXT NOT NULL, -- QR μ½”λ“œμ— λ‹΄κΈ΄ κ°’ path VARCHAR(255) NOT NULL, -- 이미지 파일 μ €μž₯ 경둜 created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
SQL
볡사

μ½”λ“œ

# QR μ½”λ“œ 생성 및 관리 GUI ν”„λ‘œκ·Έλž¨ # μ–Έμ–΄: Python 3.13 # GUI: tkinter # QR μ½”λ“œ 생성: qrcode # DB: mysql-connector-python import tkinter as tk from tkinter import ttk, filedialog, messagebox import qrcode import os import uuid from datetime import datetime import mysql.connector # DB μ—°κ²° μ„€μ • # μ‚¬μš©μž: python, λΉ„λ°€λ²ˆν˜Έ: 123456 # DB 이름은 κΈ°μ‘΄κ³Ό λ™μΌν•˜κ²Œ μ‚¬μš© (qr_code) db_config = { 'host': 'localhost', 'user': 'python', 'password': '123456', 'database': 'python' } # DB μ—°κ²° ν•¨μˆ˜ def get_connection(): return mysql.connector.connect(**db_config) # ν…Œμ΄λΈ” 생성 ν•¨μˆ˜ (QR μ½”λ“œ ν…Œμ΄λΈ”μ΄ 없을 경우 생성) def create_table_if_not_exists(): conn = get_connection() cursor = conn.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS qr_code ( no INT AUTO_INCREMENT PRIMARY KEY, id VARCHAR(36) NOT NULL, name VARCHAR(100) NOT NULL, value TEXT NOT NULL, path TEXT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL ); """) conn.commit() cursor.close() conn.close() # ν”„λ‘œκ·Έλž¨ μ‹œμž‘ μ‹œ ν…Œμ΄λΈ” 확인 및 생성 create_table_if_not_exists() # QR μ½”λ“œ μ €μž₯ ν•¨μˆ˜ def save_qr_to_db(qr_id, name, value, path): conn = get_connection() cursor = conn.cursor() now = datetime.now() cursor.execute(""" INSERT INTO qr_code (id, name, value, path, created_at, updated_at) VALUES (%s, %s, %s, %s, %s, %s) """, (qr_id, name, value, path, now, now)) conn.commit() cursor.close() conn.close() # QR μ½”λ“œ μˆ˜μ • ν•¨μˆ˜ def update_qr_name(qr_no, new_name): conn = get_connection() cursor = conn.cursor() now = datetime.now() cursor.execute(""" UPDATE qr_code SET name=%s, updated_at=%s WHERE no=%s """, (new_name, now, qr_no)) conn.commit() cursor.close() conn.close() # QR μ½”λ“œ μ‚­μ œ ν•¨μˆ˜ def delete_qr(qr_no): conn = get_connection() cursor = conn.cursor() cursor.execute("SELECT path FROM qr_code WHERE no=%s", (qr_no,)) result = cursor.fetchone() if result: try: os.remove(result[0]) except: pass cursor.execute("DELETE FROM qr_code WHERE no=%s", (qr_no,)) conn.commit() cursor.close() conn.close() # QR μ½”λ“œ 생성 ν•¨μˆ˜ def generate_qr(): name = entry_name.get() value = entry_value.get() folder = entry_path.get() if not (name and value and folder): messagebox.showerror("μž…λ ₯ 였λ₯˜", "λͺ¨λ“  ν•„λ“œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”.") return qr_id = str(uuid.uuid4()) timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") filename = f"{timestamp}_{name}.png" full_path = os.path.join(folder, filename) img = qrcode.make(value) img.save(full_path) save_qr_to_db(qr_id, name, value, full_path) messagebox.showinfo("μ™„λ£Œ", f"QR μ½”λ“œκ°€ μ €μž₯λ˜μ—ˆμŠ΅λ‹ˆλ‹€: {full_path}") refresh_dashboard() # λŒ€μ‹œλ³΄λ“œ κ°±μ‹  def refresh_dashboard(): for row in tree.get_children(): tree.delete(row) conn = get_connection() cursor = conn.cursor() cursor.execute("SELECT no, name, value, path FROM qr_code") for (no, name, value, path) in cursor.fetchall(): tree.insert('', 'end', values=(no, name, value, path)) cursor.close() conn.close() # μ„ νƒλœ ν•­λͺ©μ—μ„œ μˆ˜μ • def on_edit(): selected = tree.focus() if not selected: messagebox.showwarning("선택 μ—†μŒ", "μˆ˜μ •ν•  QR μ½”λ“œλ₯Ό μ„ νƒν•˜μ„Έμš”.") return values = tree.item(selected, 'values') qr_no = values[0] new_name = simple_input("QR μ½”λ“œ 이름 μˆ˜μ •", "μƒˆ 이름을 μž…λ ₯ν•˜μ„Έμš”:", values[1]) if new_name: update_qr_name(qr_no, new_name) refresh_dashboard() # μ„ νƒλœ ν•­λͺ© μ‚­μ œ def on_delete(): selected = tree.focus() if not selected: messagebox.showwarning("선택 μ—†μŒ", "μ‚­μ œν•  QR μ½”λ“œλ₯Ό μ„ νƒν•˜μ„Έμš”.") return values = tree.item(selected, 'values') qr_no = values[0] if messagebox.askyesno("μ‚­μ œ 확인", "정말 μ‚­μ œν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?"): delete_qr(qr_no) refresh_dashboard() # κ°„λ‹¨ν•œ μž…λ ₯μ°½ ν•¨μˆ˜ def simple_input(title, prompt, default_value=''): popup = tk.Toplevel() popup.title(title) popup.grab_set() tk.Label(popup, text=prompt).pack(padx=10, pady=5) input_var = tk.StringVar(value=default_value) entry = ttk.Entry(popup, textvariable=input_var) entry.pack(padx=10, pady=5) entry.focus() result = {'value': None} def submit(): result['value'] = input_var.get() popup.destroy() ttk.Button(popup, text="확인", command=submit).pack(pady=5) popup.wait_window() return result['value'] # GUI μ„€μ • root = tk.Tk() root.title("QR μ½”λ“œ 생성 및 관리") root.geometry("800x600") frame_input = ttk.LabelFrame(root, text="QR μ½”λ“œ 정보 μž…λ ₯") frame_input.pack(fill="x", padx=10, pady=5) entry_name = ttk.Entry(frame_input, width=50) entry_value = ttk.Entry(frame_input, width=50) entry_path = ttk.Entry(frame_input, width=50) btn_browse = ttk.Button(frame_input, text="폴더 선택", command=lambda: entry_path.insert(0, filedialog.askdirectory() + '/')) entry_name.grid(row=0, column=1, padx=5, pady=5) entry_value.grid(row=1, column=1, padx=5, pady=5) entry_path.grid(row=2, column=1, padx=5, pady=5) btn_browse.grid(row=2, column=2, padx=5) tt_label = ["QR μ½”λ“œ 이름:", "QR μ½”λ“œ κ°’:", "μ €μž₯ 경둜:"] for i, txt in enumerate(tt_label): ttk.Label(frame_input, text=txt).grid(row=i, column=0, sticky="e", padx=5, pady=5) btn_generate = ttk.Button(root, text="QR μ½”λ“œ 생성", command=generate_qr) btn_generate.pack(pady=10) frame_dashboard = ttk.LabelFrame(root, text="QR μ½”λ“œ λŒ€μ‹œλ³΄λ“œ") frame_dashboard.pack(fill="both", expand=True, padx=10, pady=10) cols = ("번호", "이름", "κ°’", "파일 경둜") tree = ttk.Treeview(frame_dashboard, columns=cols, show='headings') for col in cols: tree.heading(col, text=col) tree.column(col, width=150) tree.pack(fill="both", expand=True) btn_edit = ttk.Button(root, text="QR μ½”λ“œ 이름 μˆ˜μ •", command=on_edit) btn_delete = ttk.Button(root, text="QR μ½”λ“œ μ‚­μ œ", command=on_delete) btn_edit.pack(pady=5) btn_delete.pack(pady=5) refresh_dashboard() root.mainloop()
Python
볡사