728x90
반응형
사용자가 평균기온을 입력하면 그 값에 맞는 옷차림을 설명 코드
import tkinter as tk
from tkinter import messagebox
from PIL import Image, ImageTk
def get_clothing(temp):
if temp < 10:
return "겨울 옷차림 (코트, 목도리, 장갑)", "winter.png"
elif temp < 20:
return "가을 옷차림 (자켓, 스웨터)", "autumn.png"
else:
return "여름 옷차림 (반팔, 반바지)", "summer.png"
def show():
try:
temperature = float(entry.get())
suggestion, image_path = get_clothing(temp)
suggestion_label.config(text=suggestion)
img = Image.open(image_path) # 이미지 불러오기
img = img.resize((100, 100))
photo = ImageTk.PhotoImage(img)
image_label.config(image=photo)
image_label.image = photo
except ValueError:
messagebox.showerror("오류", "유효한 온도를 입력하세요.")
root = tk.Tk()
root.title("옷차림 추천 프로그램")
root.geometry("400x300")
entry_label = tk.Label(root, text="온도 (°C):")
entry_label.pack()
entry = tk.Entry(root)
entry.pack()
show_button = tk.Button(root, text="추천 보기", command=show)
show_button.pack()
suggestion_label = tk.Label(root, text="")
suggestion_label.pack()
image_label = tk.Label(root)
image_label.pack()
root.mainloop()
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 문제 : turtle-임의의 위치에 원,삼각형,사각형 등 그리기 (4) | 2023.12.05 |
---|---|
[파이썬] 문제 : 경마 게임 코드 (0) | 2023.12.04 |
[C언어] 학생 구조체 만들기 (2) | 2023.12.03 |
[파이썬] 문제 : 학생 점수 파일을 읽어 최저점수,최고점수,평균 구하기 (2) | 2023.12.03 |
[파이썬] 문제 : while로 100~1까지 10개씩 출력하시 (1) | 2023.12.03 |
댓글