기 타 메인보드님 한번만봐주세요
2026.02.07 14:35
파이썬 공부중인데
import os
import sys
import subprocess
import tkinter as tk
from tkinter import ttk, messagebox
from PIL import Image, ImageTk
# ==================================================
# 실행 파일 기준 경로
# ==================================================
def get_base_dir():
if getattr(sys, 'frozen', False):
# exe로 실행 시 exe 위치
return os.path.dirname(sys.executable)
return os.path.dirname(os.path.abspath(__file__))
BASE_DIR = get_base_dir()
ICON_DIR = os.path.join(BASE_DIR, "icons")
DEFAULT_ICON = os.path.join(ICON_DIR, "기본아이콘.ico")
BG_IMAGE = os.path.join(ICON_DIR, "backg.jpg")
# ==================================================
# UI 설정
# ==================================================
ICON_SIZE = 48
ITEM_W = 120
ITEM_H = 90
GAP_X = 10
GAP_Y = 10
FONT_SIZE = 9
START_X = 40
START_Y = 80
MAX_COL = 7
# ==================================================
# 프로그램 목록
# ==================================================
HOME_LIST = [
"윈도우 단축 명령어 실행 v2.5",
"전원 관리 설정 v2.0",
"디펜더 끄기",
"윈도우 헬프",
"VisualCppRedist_AIO_x86_x64"
]
AUTOCAD_LIST = [str(y) for y in range(2002, 2027)] + ["CadMas2009"]
INVENTOR_LIST = ["2019", "2022", "2024", "2026"]
HANGUL_LIST = ["2002","2005","2007","2010","2014","2016","2018","2020","2022","2023","2024"]
OFFICE_LIST = ["오피스2016","오피스2021","오피스2024"]
OFFICE_AUTH_LIST = ["오피스 인증"]
UTILITY_LIST = [
"반디집","7-ZIP","BANDIVIEW","FSViewer","KakaoTalk",
"Adobe Acrobat Pro 2024","Adobe Acrobat Pro DC 2025",
"Acrobat 7.0 Pro","AcroRdrDC2ko_KR","PotPlayer",
"SketchUpPro2026","CIMCO Edit 2025","vcnc","sscnc","노트패드3"
]
# ==================================================
# 실행 함수
# ==================================================
def run_admin(path):
path = os.path.abspath(path)
if not os.path.exists(path):
messagebox.showerror("오류", f"파일을 찾을 수 없습니다:\n{path}")
return
subprocess.Popen(
["powershell", "-Command", f"Start-Process '{path}' -Verb RunAs"],
shell=True
)
def install_program(path, exe=None):
full = os.path.join(BASE_DIR, path)
if exe:
exe_path = os.path.join(full, exe)
run_admin(exe_path if os.path.exists(exe_path) else full)
else:
run_admin(full)
# ==================================================
# GUI 생성
# ==================================================
root = tk.Tk()
root.title("소프트웨어 선택 자동 설치")
root.geometry("1020x600")
root.resizable(False, False)
btn_def = tk.Button(
root, text="Defender 실시간 보호 열기",
fg="red",
command=lambda: os.system("start ms-settings:windowsdefender")
)
btn_def.place(x=780, y=10, width=200, height=30)
notebook = ttk.Notebook(root)
notebook.place(x=10, y=50, width=1000, height=540)
# ==================================================
# 아이콘 처리
# ==================================================
icons_cache = {}
def load_icon(name, icon_file=""):
path = os.path.join(ICON_DIR, icon_file or f"{name}.ico")
if not os.path.exists(path):
path = DEFAULT_ICON
if path not in icons_cache:
img = Image.open(path).resize((ICON_SIZE, ICON_SIZE))
icons_cache[path] = ImageTk.PhotoImage(img)
return icons_cache[path]
def create_tab(tab_name, items, click_func, prefix="", icon_file=""):
frame = tk.Frame(notebook)
notebook.add(frame, text=tab_name)
if os.path.exists(BG_IMAGE):
bg = ImageTk.PhotoImage(Image.open(BG_IMAGE).resize((950, 480)))
bg_label = tk.Label(frame, image=bg)
bg_label.image = bg
bg_label.place(x=10, y=10)
row = col = 0
for name in items:
x = START_X + (ITEM_W + GAP_X) * col
y = START_Y + (ITEM_H + GAP_Y) * row
icon = load_icon(name, icon_file)
btn = tk.Button(frame, image=icon, borderwidth=0,
command=lambda n=name: click_func(n))
btn.image = icon
btn.place(x=x + 36, y=y)
lbl = tk.Label(frame, text=f"{prefix}{name}", font=("Malgun Gothic", FONT_SIZE))
lbl.place(x=x, y=y + ICON_SIZE + 5, width=ITEM_W)
lbl.bind("<Button-1>", lambda e, n=name: click_func(n))
col += 1
if col >= MAX_COL:
col = 0
row += 1
# ==================================================
# 클릭 처리
# ==================================================
def handle_home(name):
mapping = {
"윈도우 단축 명령어 실행 v2.5": r"유틸리티\윈도우 단축 명령어 실행 v2.5\윈도우 단축 명령어 실행 v2.5.exe",
"전원 관리 설정 v2.0": r"유틸리티\전원 관리 설정 v2.0\Power Managment v2.0.exe",
"디펜더 끄기": r"유틸리티\디펜더 끄기\dControl.exe",
"윈도우 헬프": r"유틸리티\윈도우 헬프\WSH.cmd",
"VisualCppRedist_AIO_x86_x64": r"유틸리티\VisualCppRedist_AIO_x86_x64\VisualCppRedist_AIO_x86_x64.exe"
}
install_program(mapping[name])
def handle_autocad(name):
install_program(fr"Autodesk\AutoCAD\AutoCAD {name}", "setup.exe")
def handle_inventor(name):
install_program(fr"Autodesk\Inventor\Inventor {name}", "setup.exe")
def handle_hangul(name):
install_program(fr"유틸리티\한글\한글 {name}", "Install.exe")
def handle_office(name):
install_program(fr"유틸리티\오피스\{name}", "setup.exe")
def handle_office_auth(_):
install_program(r"유틸리티\오피스인증\KAT.cmd")
def handle_util(name):
if name == "반디집":
install_program(r"유틸리티\반디집\Bandizip.cmd")
elif name == "BANDIVIEW":
install_program(r"유틸리티\BANDIVIEW\BANDIVIEW-SETUP-X64.EXE")
else:
install_program(fr"유틸리티\{name}", "setup.exe")
# ==================================================
# 탭 구성
# ==================================================
create_tab("홈", HOME_LIST, handle_home)
create_tab("AutoCAD", AUTOCAD_LIST, handle_autocad, "AutoCAD ", "autocad.ico")
create_tab("Inventor", INVENTOR_LIST, handle_inventor, "Inventor ", "Inventor.ico")
create_tab("한글 / 오피스", HANGUL_LIST, handle_hangul, "한글 ", "hk.ico")
create_tab("오피스", OFFICE_LIST, handle_office, "", "office.ico")
create_tab("오피스 인증", OFFICE_AUTH_LIST, handle_office_auth, "", "office.ico")
create_tab("기타 유틸리티", UTILITY_LIST, handle_util)
root.mainloop()
조금만 도와주세요 감사드립니다
댓글 [2]
| 번호 | 제목 | 글쓴이 | 조회 | 등록일 |
|---|---|---|---|---|
| [공지] | 질문과 답변 게시판 이용간 유의사항 | gooddew | - | - |
| 103471 | 윈 도 우| WinXPE_Builder2_25H2 어떻게 구하나요? | 슈퍼맨~~ | 558 | 02-10 |
| 103470 | 소프트웨어| 엑셀 매크로 문제 문의 드립니다 [2] | 이어도 | 543 | 02-09 |
| 103469 | 기 타| Microsoft 계정 비정상적인 로그인 활동 [5] | 승두아빠 | 744 | 02-09 |
| 103468 | 윈 도 우| 윈도우11 확 밀고 새로 설치 윈도우12 베타버전 없다면서요. [2] | titcat | 1037 | 02-09 |
| 103467 | 윈 도 우| 윈도우를 만들어쓰는 강좌가 있을까요? [2] | 행정학도 | 536 | 02-09 |
| 103466 | 소프트웨어| 멀웨어 라고 지칭되는 파일이 계속 생겨요 [7] | 송구장이 | 636 | 02-09 |
| 103465 | 서버 / IT| 랜툴 (관통형 아님) 질문입니다^^ [5] | 개울소리 | 514 | 02-09 |
| 103464 | 기 타| 로컬 네트워크 속도관련 문의 [11] | magoo | 494 | 02-09 |
| 103463 | 기 타| 구글 ai제미니한테 [6] | 덥다 | 713 | 02-09 |
| 103462 | 윈 도 우| 크롬 시작화면이 바뀌었어요 [1] | 禮儀 | 871 | 02-08 |
| 103461 | 윈 도 우| 【PE】 딸랑쇠님의 카조_Win11_Ultimate_iso-mount PE 프로... [2] | 홍은동초짜 | 1208 | 02-08 |
| 103460 | 소프트웨어| 레인미터 수정좀 해주실 고수님 부탁드려요 [1] | 영동할매 | 514 | 02-08 |
| 103459 | 소프트웨어| Imagew64 한글 언어를 이거로 바꿔주세요 [11] | #cortana# | 840 | 02-07 |
| 103458 | 소프트웨어| 이지드라이버나 드라이버 통합 설치 팩 최신버전 구해요 [3] | 복동이달려 | 717 | 02-07 |
| 103457 | 윈 도 우| 새 컴퓨터에 기존 VHD 연결 방법이 궁금합니다. [7] | JANSON | 526 | 02-07 |
| 103456 | 윈 도 우| [Q] rededit 화일 좀 [2] | 통도리 | 393 | 02-07 |
| » | 기 타| 메인보드님 한번만봐주세요 [2] | 천사케이 | 627 | 02-07 |
| 103454 | 기 타| 크롬에서 윈도우 포럼 의 탭 메뉴가 보이질 않습니다 [2] | 선우아버 | 304 | 02-07 |
| 103453 | 소프트웨어| everything toolbar 좀 사용해 보려는데 작동을 안 하네요 [2] | naver | 326 | 02-07 |
| 103452 | 기 타| 벽면에 설치된 동축케이블tv선 [6] | 하늘세상 | 830 | 02-07 |
ModuleNotFOundError: No module named 'PIL'의 에러는 말 그대로 소스상에서 사용하겠다고 PIL을 import 하였지만, 해당 패키지가 없다는것입니다.
cmd 창을 열고 아래의 명령어를 입력 후 재시도해보세요.
pip install pillow
그리고 올려주신 소스에 문제가있어서 한번 수정해봤습니다.
import os
import sys
import subprocess
import tkinter as tk
from tkinter import ttk, messagebox
from PIL import Image, ImageTk
# ==================================================
# 실행 파일 기준 경로
# ==================================================
def get_base_dir():
if getattr(sys, 'frozen', False):
return os.path.dirname(sys.executable)
return os.path.dirname(os.path.abspath(__file__))
BASE_DIR = get_base_dir()
ICON_DIR = os.path.join(BASE_DIR, "icons")
DEFAULT_ICON = os.path.join(ICON_DIR, "기본아이콘.ico")
BG_IMAGE = os.path.join(ICON_DIR, "backg.jpg")
# ==================================================
# UI 설정
# ==================================================
ICON_SIZE = 48
ITEM_W = 120
ITEM_H = 90
GAP_X = 10
GAP_Y = 10
FONT_SIZE = 9
START_X = 40
START_Y = 80
MAX_COL = 7
# ==================================================
# 프로그램 목록
# ==================================================
HOME_LIST = [
"윈도우 단축 명령어 실행 v2.5",
"전원 관리 설정 v2.0",
"디펜더 끄기",
"윈도우 헬프",
"VisualCppRedist_AIO_x86_x64"
]
AUTOCAD_LIST = [str(y) for y in range(2002, 2027)] + ["CadMas2009"]
INVENTOR_LIST = ["2019", "2022", "2024", "2026"]
HANGUL_LIST = ["2002","2005","2007","2010","2014","2016","2018","2020","2022","2023","2024"]
OFFICE_LIST = ["오피스2016","오피스2021","오피스2024"]
OFFICE_AUTH_LIST = ["오피스 인증"]
UTILITY_LIST = [
"반디집","7-ZIP","BANDIVIEW","FSViewer","KakaoTalk",
"Adobe Acrobat Pro 2024","Adobe Acrobat Pro DC 2025",
"Acrobat 7.0 Pro","AcroRdrDC2ko_KR","PotPlayer",
"SketchUpPro2026","CIMCO Edit 2025","vcnc","sscnc","노트패드3"
]
# ==================================================
# 실행 함수
# ==================================================
def run_admin(path):
path = os.path.abspath(path)
if not os.path.exists(path):
messagebox.showerror("오류", f"파일을 찾을 수 없습니다:\n{path}")
return
subprocess.Popen(
["powershell", "-Command", f"Start-Process '{path}' -Verb RunAs"],
shell=True
)
def install_program(path, exe=None):
full = os.path.join(BASE_DIR, path)
if not os.path.exists(full):
messagebox.showerror("오류", f"경로를 찾을 수 없습니다:\n{full}")
return
if exe:
exe_path = os.path.join(full, exe)
if os.path.exists(exe_path):
run_admin(exe_path)
else:
messagebox.showerror("오류", f"실행 파일을 찾을 수 없습니다:\n{exe_path}")
else:
if os.path.isfile(full):
run_admin(full)
else:
messagebox.showerror("오류", f"파일이 아닙니다:\n{full}")
# ==================================================
# GUI 생성
# ==================================================
root = tk.Tk()
root.title("소프트웨어 선택 자동 설치")
root.geometry("1020x600")
root.resizable(False, False)
btn_def = tk.Button(
root, text="Defender 실시간 보호 열기",
fg="red",
command=lambda: os.system("start ms-settings:windowsdefender")
)
btn_def.place(x=780, y=10, width=200, height=30)
notebook = ttk.Notebook(root)
notebook.place(x=10, y=50, width=1000, height=540)
# ==================================================
# 아이콘 처리
# ==================================================
icons_cache = {}
def load_icon(name, icon_file=""):
path = os.path.join(ICON_DIR, icon_file or f"{name}.ico")
if not os.path.exists(path):
path = DEFAULT_ICON
if path not in icons_cache:
img = Image.open(path).resize((ICON_SIZE, ICON_SIZE))
icons_cache[path] = ImageTk.PhotoImage(img)
return icons_cache[path]
def create_tab(tab_name, items, click_func, prefix="", icon_file=""):
frame = tk.Frame(notebook)
notebook.add(frame, text=tab_name)
if os.path.exists(BG_IMAGE):
bg = ImageTk.PhotoImage(Image.open(BG_IMAGE).resize((950, 480)))
bg_label = tk.Label(frame, image=bg)
bg_label.image = bg
bg_label.place(x=10, y=10)
row = col = 0
for name in items:
x = START_X + (ITEM_W + GAP_X) * col
y = START_Y + (ITEM_H + GAP_Y) * row
icon = load_icon(name, icon_file)
btn = tk.Button(frame, image=icon, borderwidth=0,
command=lambda n=name: click_func(n))
btn.image = icon
btn.place(x=x + 36, y=y)
lbl = tk.Label(frame, text=f"{prefix}{name}", font=("Malgun Gothic", FONT_SIZE))
lbl.place(x=x, y=y + ICON_SIZE + 5, width=ITEM_W)
lbl.bind("<Button-1>", lambda e, n=name: click_func(n))
col += 1
if col >= MAX_COL:
col = 0
row += 1
# ==================================================
# 클릭 처리
# ==================================================
def handle_home(name):
mapping = {
"윈도우 단축 명령어 실행 v2.5": r"유틸리티\윈도우 단축 명령어 실행 v2.5\윈도우 단축 명령어 실행 v2.5.exe",
"전원 관리 설정 v2.0": r"유틸리티\전원 관리 설정 v2.0\Power Managment v2.0.exe",
"디펜더 끄기": r"유틸리티\디펜더 끄기\dControl.exe",
"윈도우 헬프": r"유틸리티\윈도우 헬프\WSH.cmd",
"VisualCppRedist_AIO_x86_x64": r"유틸리티\VisualCppRedist_AIO_x86_x64\VisualCppRedist_AIO_x86_x64.exe"
}
install_program(mapping[name])
def handle_autocad(name):
install_program(fr"Autodesk\AutoCAD\AutoCAD {name}", "setup.exe")
def handle_inventor(name):
install_program(fr"Autodesk\Inventor\Inventor {name}", "setup.exe")
def handle_hangul(name):
install_program(fr"유틸리티\한글\한글 {name}", "Install.exe")
def handle_office(name):
install_program(fr"유틸리티\오피스\{name}", "setup.exe")
def handle_office_auth(_):
install_program(r"유틸리티\오피스인증\KAT.cmd")
def handle_util(name):
# 각 프로그램별 정확한 경로와 실행파일 매핑
mapping = {
"반디집": (r"유틸리티\반디집", "Bandizip.cmd"),
"7-ZIP": (r"유틸리티\7-ZIP", "setup.exe"),
"BANDIVIEW": (r"유틸리티\BANDIVIEW", "BANDIVIEW-SETUP-X64.EXE"),
"FSViewer": (r"유틸리티\FSViewer", "setup.exe"),
"KakaoTalk": (r"유틸리티\KakaoTalk", "setup.exe"),
"Adobe Acrobat Pro 2024": (r"유틸리티\Adobe Acrobat Pro 2024", "setup.exe"),
"Adobe Acrobat Pro DC 2025": (r"유틸리티\Adobe Acrobat Pro DC 2025", "setup.exe"),
"Acrobat 7.0 Pro": (r"유틸리티\Acrobat 7.0 Pro", "setup.exe"),
"AcroRdrDC2ko_KR": (r"유틸리티\AcroRdrDC2ko_KR", "setup.exe"),
"PotPlayer": (r"유틸리티\PotPlayer", "setup.exe"),
"SketchUpPro2026": (r"유틸리티\SketchUpPro2026", "setup.exe"),
"CIMCO Edit 2025": (r"유틸리티\CIMCO Edit 2025", "setup.exe"),
"vcnc": (r"유틸리티\vcnc", "setup.exe"),
"sscnc": (r"유틸리티\sscnc", "setup.exe"),
"노트패드3": (r"유틸리티\노트패드3", "setup.exe")
}
if name in mapping:
path, exe = mapping[name]
install_program(path, exe)
else:
messagebox.showerror("오류", f"'{name}' 프로그램 정보를 찾을 수 없습니다.")
# ==================================================
# 탭 구성
# ==================================================
create_tab("홈", HOME_LIST, handle_home)
create_tab("AutoCAD", AUTOCAD_LIST, handle_autocad, "AutoCAD ", "autocad.ico")
create_tab("Inventor", INVENTOR_LIST, handle_inventor, "Inventor ", "Inventor.ico")
create_tab("한글", HANGUL_LIST, handle_hangul, "한글 ", "hk.ico")
create_tab("오피스", OFFICE_LIST, handle_office, "", "office.ico")
create_tab("오피스 인증", OFFICE_AUTH_LIST, handle_office_auth, "", "office.ico")
create_tab("기타 유틸리티", UTILITY_LIST, handle_util)
root.mainloop()