소스 코드 제출
import pygame
import pygame_textinput
import sys
import winsound
from datetime import datetime
# 초기화
pygame.init()
# 화면 설정
WIDTH, HEIGHT = 600, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("하루 일정 관리 (3시 ~ 10시)")
# 한글 폰트 설정 (환경에 맞게 경로 수정)
font_path = "C:/Windows/Fonts/malgun.ttf"
font = pygame.font.Font(font_path, 22)
big_font = pygame.font.Font(font_path, 36)
# 색상 정의
WHITE = (255, 255, 255)
GRAY = (200, 200, 200)
DARK_GRAY = (150, 150, 150)
BLACK = (0, 0, 0)
GREEN = (0, 200, 0)
BLUE = (165, 205, 255)
RED = (255, 25, 50)
# 시간대
START_HOUR = 3
END_HOUR = 10
# 상태 변수
tasks = {}
text_inputs = {} # 시간별 입력 객체
active_input = None
score = 0
x = 0
rfile = open("C:\\Users\\user\\PycharmProjects\\PythonProject3\\20251015(txt).txt", 'r')
while True:
line = rfile.readline()
if not line:
break
tasks[3 + x] = {
"text": line
}
text_inputs[3 + x] = pygame_textinput.TextInputVisualizer(font_object=font)
x += 1
rfile.close()
for i, hour in enumerate(range(START_HOUR + x, END_HOUR + 1)):
tasks[hour] = {
"text": ""
}
text_inputs[hour] = pygame_textinput.TextInputVisualizer(font_object=font)
for i, hour in enumerate(range(START_HOUR, END_HOUR + 1)):
tasks[hour] = {
"completed": False,
"rect": pygame.Rect(50, 80 + i * 60, 300, 40),
"btn_rect": pygame.Rect(370, 80 + i * 60, 100, 40)
}
# 입력 박스를 눌렀을 때
def handle_click(pos):
global active_input
for hour, task in tasks.items():
if task["rect"].collidepoint(pos) and not task["completed"]:
active_input = hour
text_inputs[hour].value = task["text"]
elif task["btn_rect"].collidepoint(pos):
if task["text"] and not task["completed"]:
task["completed"] = True
if datetime.now().hour - 12 <= hour:
global score
score += 1
if active_input == hour:
active_input = None
# 키보드 이벤트 처리
def handle_key(event):
global active_input
if active_input is not None:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
tasks[active_input]["text"] = text_inputs[active_input].value
active_input = None
# 화면 그리기
def draw(events):
global score
screen.fill(WHITE)
# 점수 표시
score_text = big_font.render(f"점수: {score}", True, BLACK)
screen.blit(score_text, (50, 20))
# 일정들
for hour, task in tasks.items():
# 색상 결정
color = DARK_GRAY if task["completed"] else (BLUE if active_input == hour else GRAY)
pygame.draw.rect(screen, color, task["rect"])
# 시간 텍스트 출력
time_text = font.render(f"{hour}시", True, BLACK)
screen.blit(time_text, (task["rect"].x - 45, task["rect"].y + 8))
# 입력 중이면 textinput 사용
if active_input == hour:
text_inputs[hour].update(events)
screen.blit(text_inputs[hour].surface, (task["rect"].x + 5, task["rect"].y + 5))
elif task["text"]:
text_surface = font.render(task["text"], True, BLACK)
screen.blit(text_surface, (task["rect"].x + 10, task["rect"].y + 8))
# 버튼 그리기
enabled = bool(task["text"]) and not task["completed"]
if enabled:
btn_color = GREEN
pygame.draw.rect(screen, btn_color, task["btn_rect"])
btn_text = font.render("완료하기", True, WHITE)
elif task["completed"]:
btn_color = RED
pygame.draw.rect(screen, btn_color, task["btn_rect"])
btn_text = font.render("완료함", True, WHITE)
else:
btn_color = DARK_GRAY
pygame.draw.rect(screen, btn_color, task["btn_rect"])
btn_text = font.render("일정 없음", True, WHITE)
screen.blit(btn_text, (task["btn_rect"].x + 3, task["btn_rect"].y + 8))
pygame.display.flip()
# 메인 루프
def main():
clock = pygame.time.Clock()
while True:
events = pygame.event.get() # 한 번만 호출!
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
handle_click(event.pos)
elif event.type == pygame.KEYDOWN:
handle_key(event)
draw(events)
if datetime.now().minute == 0:
winsound.Beep(1000, 5000)
clock.tick(30)
main()
좋아요



