본문 바로가기

개발 교육

ChatGPT야 프로그램 좀 만들어줄래?

728x90

2021.10.25 - [개발 교육] - 오늘은 스파르타 코딩 웹개발 1일차

 

오늘은 스파르타 코딩 웹개발 1일차

오늘은 스파르타 코딩 OT날 바로 줌으로 들어가서 오티를 들었다. 매니져 님이 활발해서 좋은듯 하다. 하지만 1주차 수업을 듣기 시작하자마자 뭔소린지 모르겠다. ㅠ_ㅠ 그래도 시작이 반이라고

rebil85.tistory.com

나는 2021년에 국비지원사업으로 스파르타 코딩이라는 사이트에서 홈페이지를 만드는 교육을 받은 적이있다.
물론 현재는 홈페이지를 만들기는 커녕 기존에 알고 있던 함수나 용어까지 까먹은 상태다. 하고 있는 일이 홈페이지와 전혀 상관없는 일이기 때문이다. 

그러나 이 이야기를 왜 쓰냐면
최근 회사에 다니면서 재고관리 프로그램의 필요성을 굉장히 느끼고 있던 중에 ChatGPT가 코드까지 짜준다는 것을 알고있었고 그게 생각나서 ChatGPT를 이용해서 프로그램을 짜기로 결정했다.

ChatGPT야 프로그램 좀 만들어줄래?

일단 ChatGPT로 프로그램을 만들기 위해서는 잘 물어봐야지 제대로된 답변을 준다고 한다.
그래서 테스트겸 간단한 질문을 던져 봤다.

안녕. 너는 지금부터 프로그램 코딩 전문가야.
그래서 내가 윈도우에서 쓸수있는 프로그램을 만들어줬으면 좋겠어.
내가 원하는 프로그램은 파이썬으로 만들고 싶고

사용 목적은 재고관리 프로그램을 만들고 싶어

프로그램에 사용되는 모든 글씨체는 "고딕체"이고
첫화면에서는 타이틀은 상단에 가운데 정렬해서 "회사명" 이라고 나오게 하고

그 밑으로는 버튼 세개가 있는데 재고 입력 버튼, 재고 확인 버튼, 종료 버튼이 나오게 만들고
각이 동그란 모서리인 버튼 두개를 만들어줘

종료 버튼을 누르면 프로그램이 종료되게 해줘

재고 입력 버튼을 누르면 나오는 화면에서는 위에서 부터 아래로 글을 적을수 있는 빈칸이 나오고 빈칸 왼쪽 위 상단에는 글이 적혀있고 순서대로 매장명, 바코드 1, 바코드 2, 제품명, 기본 수량, 입고 수량, 위치, 비고 순서대로 빈칸 왼쪽 상단에 적혀있어.

그 빈칸에다가 글을 치면 데이터베이스로 저장되는 방식의 프로그램이야.
데이터베이스 저장 방식은 엑셀로 저장이 되고 데이터베이스를 불러올때도 엑셀에서 불러왔으면 좋겠어 종료 버튼을 누르면 첫화면으로 다시 가게 만들어줘 재고 확인버튼을 눌렀을때 나오는 화면은 제일 위에는 "재고 확인" 이라는 글자와 오른쪽에는 "종료"라는 버튼이 있고 그 아래에 내용은 보이는 UI는 표 형태로 한눈에 보기쉽게 해주고. 엑셀에서 불러온 데이터베이스에서 1행에는 "위치", "제품명", "비고" 행으로 나오고 글자는 굵게해줘 위에 종료 버튼을 누르면 첫번째 화면으로 돌아갈수있게 해줘

라고 질문을 넣었고
1차 수정 2차 수정을 거쳐

import tkinter as tk
from tkinter import messagebox
import pandas as pd

# Create a DataFrame for the database
database_path = "inventory_database.xlsx"
try:
    inventory_df = pd.read_excel(database_path)
except FileNotFoundError:
    inventory_df = pd.DataFrame(columns=["매장명", "바코드1", "바코드2", "제품명", "기본수량", "입고수량", "위치", "현재고", "비고"])
    inventory_df.to_excel(database_path, index=False)

def save_to_database(data):
    global inventory_df
    new_row = pd.Series(data)
    try:
        inventory_df = pd.concat([inventory_df, new_row.to_frame().transpose()], ignore_index=True)
        inventory_df.to_excel(database_path, index=False)
    except PermissionError:
        messagebox.showerror("Error", "Please close the Excel file before saving.")

def show_inventory():
    try:
        inventory_df = pd.read_excel(database_path)
        if "현재고" not in inventory_df.columns:
            messagebox.showinfo("알림", "데이터베이스에 '현재고' 열이 없습니다.")
            return

        inventory_df = inventory_df[["위치", "제품명", "현재고", "비고"]]
        inventory_table = tk.Toplevel(root)
        inventory_table.title("재고 확인")

        # Display data in a table format with bold headers
        headers = ["위치", "제품명", "현재고", "비고"]
        for header in headers:
            tk.Label(inventory_table, text=header, font=("Arial", 12, "bold")).pack(side=tk.LEFT, padx=20)

        tk.Frame(inventory_table, height=2, bd=1, relief=tk.SUNKEN).pack(fill=tk.X, padx=20, pady=5)

        for index, row in inventory_df.iterrows():
            for col in headers:
                tk.Label(inventory_table, text=row[col], font=("Arial", 10)).pack(side=tk.LEFT, padx=20)
            tk.Frame(inventory_table, height=1, bd=1, relief=tk.SUNKEN).pack(fill=tk.X, padx=20)

        exit_button = tk.Button(inventory_table, text="종료", command=inventory_table.destroy, font=("Arial", 12))
        exit_button.pack(pady=20)
    except FileNotFoundError:
        messagebox.showinfo("알림", "데이터베이스가 비어 있습니다.")

def show_input_screen():
    input_screen = tk.Toplevel(root)
    input_screen.title("재고 입력")

    # Increase the height of the "재고 입력" screen
    input_screen.geometry("400x800+200+150")

    labels = ["매장명", "바코드1", "바코드2", "제품명", "기본수량", "입고수량", "위치", "비고"]
    entries = []

    for label in labels:
        tk.Label(input_screen, text=label, font=("Arial", 16)).pack(pady=5)
        entry = tk.Entry(input_screen, font=("Arial", 14))
        entry.pack(pady=5)
        entries.append(entry)

    def save_and_exit():
        data = {label: entry.get() for label, entry in zip(labels, entries)}
        save_to_database(data)
        messagebox.showinfo("알림", "데이터가 저장되었습니다.")
        input_screen.destroy()

    # Save button centered
    save_button = tk.Button(input_screen, text="저장", command=save_and_exit, font=("Arial", 16))
    save_button.pack(pady=20)

    # Exit button centered
    exit_button = tk.Button(input_screen, text="종료", command=input_screen.destroy, font=("Arial", 16))
    exit_button.pack(pady=20)

# Main Screen
root = tk.Tk()
root.title("회사명")

# Set a fixed size for the main window
root.geometry("400x400+200+100")

# Change the font to Gothic for the entire program
font_style = ("Gothic", 12)

# Title
title_label = tk.Label(root, text="회사명", font=("Gothic", 30))
title_label.pack(pady=20)

# Buttons
input_button = tk.Button(root, text="재고 입력", command=show_input_screen, font=font_style, bd=5)
input_button.pack(pady=20)

check_button = tk.Button(root, text="재고 확인", command=show_inventory, font=font_style, bd=5)
check_button.pack(pady=20)

exit_button = tk.Button(root, text="종료", command=root.destroy, font=font_style, bd=5)
exit_button.pack(pady=20)

root.mainloop()

이런 코드를 송출

재고프로그램 타이틀
재고관리 입력창

이런 프로그램으로 만들어내기 시작했다.

와 씨 대박! 
절로 웃음이 나왔고 현재도 계속 수정이 진행중이다. 
혹시 나중에 완성이 된다면 올려보도록 하겠다.

728x90