728x90
IntelliJ나 vscode와 같은 개발IDE 툴 또한 프로그래밍 언어를 통해 개발되었기에
흥미가 생겨 ChatGPT를 이용해 간단하게 IDE툴을 만들어보았다.
실제 사용은 어렵기도 하고 할 필요도 없고 그냥 이런것도 가능하다 정도만 알면 될거같다.
simple_ide.py
import tkinter as tk
from tkinter import filedialog, messagebox
import subprocess
class SimpleIDE:
def __init__(self, root):
self.root = root
self.root.title("Simple IDE")
self.root.geometry("800x600")
# 코드 입력 텍스트 영역
self.editor = tk.Text(root, wrap="word")
self.editor.pack(fill="both", expand=True)
# 메뉴 생성
self.create_menu()
def create_menu(self):
menubar = tk.Menu(self.root)
# 파일 메뉴
file_menu = tk.Menu(menubar, tearoff=0)
file_menu.add_command(label="New", command=self.new_file)
file_menu.add_command(label="Open", command=self.open_file)
file_menu.add_command(label="Save", command=self.save_file)
menubar.add_cascade(label="File", menu=file_menu)
# 실행 메뉴
run_menu = tk.Menu(menubar, tearoff=0)
run_menu.add_command(label="Run", command=self.run_code)
menubar.add_cascade(label="Run", menu=run_menu)
self.root.config(menu=menubar)
def new_file(self):
self.editor.delete("1.0", tk.END)
def open_file(self):
file_path = filedialog.askopenfilename(filetypes=[("Python Files", "*.py")])
if file_path:
with open(file_path, "r") as file:
self.editor.delete("1.0", tk.END)
self.editor.insert(tk.END, file.read())
def save_file(self):
file_path = filedialog.asksaveasfilename(defaultextension=".py", filetypes=[("Python Files", "*.py")])
if file_path:
with open(file_path, "w") as file:
file.write(self.editor.get("1.0", tk.END))
def run_code(self):
code = self.editor.get("1.0", tk.END)
with open("temp_code.py", "w") as file:
file.write(code)
result = subprocess.run(["python", "temp_code.py"], capture_output=True, text=True)
messagebox.showinfo("Execution Result", result.stdout if result.stdout else result.stderr)
if __name__ == "__main__":
root = tk.Tk()
ide = SimpleIDE(root)
root.mainloop()
추가적으로 실행파일(exec)로 변환해서 실행하기 위한방법 참고(Pyinstaller이용)
pip install pyinstaller
//OR
brew install pyinstaller //(Mac)
pyinstaller --onefile --windowed --icon=my_icon.ico simple_ide.py
//OR
pyinstaller --onefile --windowed --icon=my_icon.icns simple_ide.py //Mac의경우
728x90
'프로그래밍 > Python' 카테고리의 다른 글
Python을 이용하여 youtube 크롤링(Google Cloud API활용) (2) | 2024.10.20 |
---|---|
Python을 이용해 네이버 뉴스 크롤링 및 CSV저장 해보기 (3) | 2024.10.20 |
파이썬 Selenium 사용해보기 (0) | 2024.10.19 |