본문 바로가기
다양한 TIP

python으로 만드는 성경찾기 프로그램(GenCG Text 형식)

by 유기농프로그래밍 2023. 8. 19.
반응형

선행학습

아래의 네가지 글을 다 이해하고 적용할 줄 안다면 아래의 프로그램을 대략적으로 이해할 수 있습니다.

 

python 간단한 윈도우 ui 만들기(tkinter, ttk)

 

python tkinter 크기조절(윈도우, 위젯)

 

python tkinter를 이용한 GUI 그리기 - 여러 위젯 사용하기

 

python tkinter 위젯 위치조절 하는 방법(place)

 

성경찾기 프로그램

README

성경찾는 프로그램입니다. 개역개정을 기반으로 작성하여 만들었으며 첨부파일의 bible.txt가 필요합니다.

위치는 C드라이브에 MC 폴더를 만들어서 bible.txt를 넣어줘야합니다.

성경 텍스트 파일 경로를 직접 코드수정해서 변경하셔도 됩니다.

 

저장버튼을 누르면 해당 결과 text 내용이 바탕화면에 오늘 날짜로 파일생성이 됩니다.

ex) bible_verse_2023-08-19

 

출력파일 인코딩은 ansi로 했습니다. GenCG에서는 UTF-8은 인식을 못하더라구요.

 

코드파일

#!/usr/bin/python3

import os
from datetime import datetime
import tkinter as tk
from tkinter import ttk
from tkinter import scrolledtext
from tkinter import messagebox

class BibleApp:
    def __init__(self):
        self.file_path = 'C:\\MC\\bible.txt'  # 성경 텍스트 파일 경로
        with open(self.file_path, 'r', encoding='utf-8') as f:
            self.bible_text = f.read()
            self.lines = self.bible_text.split('\n')
        self.chapter_verse = {'창': {1: 31, 2: 25, 3: 24, 4: 26, 5: 32, 6: 22, 7: 24, 8: 22, 9: 29, 10: 32, 11: 32, 12: 20, 13: 18, 14: 24, 15: 21, 16: 16, 17: 27, 18: 33, 19: 38, 20: 18, 21: 34, 22: 24, 23: 20, 24: 67, 25: 34, 26: 35, 27: 46, 28: 22, 29: 35, 
30: 43, 31: 55, 32: 32, 33: 20, 34: 31, 35: 29, 36: 43, 37: 36, 38: 30, 39: 23, 40: 23, 41: 57, 42: 38, 43: 34, 44: 34, 45: 28, 46: 34, 47: 31, 48: 22, 49: 33, 50: 26}, '출': {1: 22, 2: 25, 3: 22, 4: 31, 5: 23, 6: 30, 7: 25, 8: 32, 9: 35, 10: 29, 11: 10, 12: 51, 13: 22, 14: 31, 15: 27, 16: 36, 17: 16, 18: 27, 19: 25, 20: 26, 21: 36, 22: 30, 23: 33, 24: 18, 25: 40, 26: 37, 27: 21, 28: 43, 29: 46, 30: 38, 31: 18, 32: 35, 33: 23, 34: 35, 35: 35, 36: 38, 37: 29, 38: 31, 39: 43, 40: 38}, '레': {1: 17, 2: 16, 3: 17, 4: 35, 5: 19, 6: 30, 7: 38, 8: 36, 9: 24, 10: 20, 11: 47, 12: 8, 13: 59, 14: 57, 15: 33, 16: 34, 17: 16, 18: 30, 19: 37, 20: 27, 21: 24, 22: 33, 23: 44, 24: 23, 25: 55, 26: 46, 
27: 34}, '민': {1: 54, 2: 34, 3: 51, 4: 49, 5: 31, 6: 27, 7: 89, 8: 26, 9: 23, 10: 36, 11: 35, 12: 16, 13: 33, 14: 45, 15: 41, 16: 50, 17: 13, 18: 32, 19: 22, 20: 29, 21: 35, 22: 41, 23: 30, 24: 25, 25: 18, 26: 65, 27: 23, 28: 31, 
29: 40, 30: 16, 31: 54, 32: 42, 33: 56, 34: 29, 35: 34, 36: 13}, '신': {1: 46, 2: 37, 3: 29, 4: 49, 5: 33, 6: 25, 7: 26, 8: 20, 9: 29, 10: 22, 11: 32, 12: 32, 13: 18, 14: 29, 15: 23, 16: 22, 17: 20, 18: 22, 19: 21, 20: 20, 21: 23, 
22: 30, 23: 25, 24: 22, 25: 19, 26: 19, 27: 26, 28: 68, 29: 29, 30: 20, 31: 30, 32: 52, 33: 29, 34: 12}, '수': {1: 18, 2: 24, 3: 17, 4: 24, 5: 15, 6: 27, 7: 25, 8: 35, 9: 27, 10: 43, 11: 23, 12: 24, 13: 33, 14: 15, 15: 63, 16: 10, 
17: 18, 18: 28, 19: 51, 20: 9, 21: 45, 22: 34, 23: 16, 24: 33}, '삿': {1: 36, 2: 23, 3: 31, 4: 24, 5: 31, 6: 40, 7: 25, 8: 35, 9: 57, 10: 18, 11: 40, 12: 15, 13: 25, 14: 20, 15: 20, 16: 31, 17: 13, 18: 31, 19: 30, 20: 48, 21: 25}, 
'룻': {1: 22, 2: 23, 3: 18, 4: 22}, '삼상': {1: 28, 2: 36, 3: 21, 4: 22, 5: 12, 6: 21, 7: 17, 8: 22, 9: 27, 10: 27, 11: 15, 12: 25, 13: 22, 14: 52, 15: 35, 16: 23, 17: 58, 18: 30, 19: 23, 20: 42, 21: 15, 22: 23, 23: 29, 24: 22, 25: 44, 26: 25, 27: 12, 28: 25, 29: 11, 30: 30, 31: 13}, '삼하': {1: 27, 2: 32, 3: 39, 4: 12, 5: 25, 6: 23, 7: 29, 8: 18, 9: 13, 10: 19, 11: 27, 12: 31, 13: 39, 14: 33, 15: 37, 16: 23, 17: 29, 18: 33, 19: 43, 20: 26, 21: 22, 22: 51, 23: 39, 24: 25}, '왕상': {1: 53, 2: 46, 3: 28, 4: 34, 5: 18, 6: 38, 7: 51, 8: 66, 9: 28, 10: 29, 11: 43, 12: 33, 13: 34, 14: 31, 15: 34, 16: 34, 17: 24, 18: 46, 19: 21, 20: 43, 21: 29, 22: 53}, '왕하': {1: 18, 2: 25, 3: 27, 4: 44, 5: 27, 6: 33, 7: 20, 8: 29, 9: 37, 10: 36, 11: 21, 12: 21, 13: 25, 14: 29, 15: 38, 16: 20, 17: 41, 18: 37, 19: 37, 20: 21, 21: 26, 22: 20, 23: 37, 24: 20, 25: 30}, '대상': {1: 54, 2: 55, 3: 24, 4: 43, 5: 26, 6: 81, 7: 40, 8: 40, 9: 
44, 10: 14, 11: 47, 12: 40, 13: 14, 14: 17, 15: 29, 16: 43, 17: 27, 18: 17, 19: 19, 20: 8, 21: 30, 22: 19, 23: 32, 24: 31, 25: 31, 26: 32, 27: 34, 28: 21, 29: 30}, '대하': {1: 17, 2: 18, 3: 17, 4: 22, 5: 14, 6: 42, 7: 22, 8: 18, 9: 31, 10: 19, 11: 23, 12: 16, 13: 22, 14: 15, 15: 19, 16: 14, 17: 19, 18: 34, 19: 11, 20: 37, 21: 20, 22: 12, 23: 21, 24: 27, 25: 28, 26: 23, 27: 9, 28: 27, 29: 36, 30: 27, 31: 21, 32: 33, 33: 25, 34: 33, 35: 27, 36: 23}, '스': {1: 
11, 2: 70, 3: 13, 4: 24, 5: 17, 6: 22, 7: 28, 8: 36, 9: 15, 10: 44}, '느': {1: 11, 2: 20, 3: 32, 4: 23, 5: 19, 6: 19, 7: 73, 8: 18, 9: 38, 10: 39, 11: 36, 12: 47, 13: 31}, '에': {1: 22, 2: 23, 3: 15, 4: 17, 5: 14, 6: 14, 7: 10, 8: 
17, 9: 32, 10: 3}, '욥': {1: 22, 2: 13, 3: 26, 4: 21, 5: 27, 6: 30, 7: 21, 8: 22, 9: 35, 10: 22, 11: 20, 12: 25, 13: 28, 14: 22, 15: 35, 16: 22, 17: 16, 18: 21, 19: 29, 20: 29, 21: 34, 22: 30, 23: 17, 24: 25, 25: 6, 26: 14, 27: 23, 28: 28, 29: 25, 30: 31, 31: 40, 32: 22, 33: 33, 34: 37, 35: 16, 36: 33, 37: 24, 38: 41, 39: 30, 40: 24, 41: 34, 42: 17}, '시': {1: 6, 2: 12, 3: 8, 4: 8, 5: 12, 6: 10, 7: 17, 8: 9, 9: 20, 10: 18, 11: 7, 12: 8, 13: 6, 14: 7, 15: 5, 
16: 11, 17: 15, 18: 50, 19: 14, 20: 9, 21: 13, 22: 31, 23: 6, 24: 10, 25: 22, 26: 12, 27: 14, 28: 9, 29: 11, 30: 12, 31: 24, 32: 11, 33: 22, 34: 22, 35: 28, 36: 12, 37: 40, 38: 22, 39: 13, 40: 17, 41: 13, 42: 11, 43: 5, 44: 26, 45: 17, 46: 11, 47: 9, 48: 14, 49: 20, 50: 23, 51: 19, 52: 9, 53: 6, 54: 7, 55: 23, 56: 13, 57: 11, 58: 11, 59: 17, 60: 12, 61: 8, 62: 12, 63: 11, 64: 10, 65: 13, 66: 20, 67: 7, 68: 35, 69: 36, 70: 5, 71: 24, 72: 19, 73: 28, 74: 23, 75: 10, 76: 12, 77: 20, 78: 72, 79: 13, 80: 19, 81: 16, 82: 8, 83: 18, 84: 12, 85: 13, 86: 17, 87: 7, 88: 18, 89: 52, 90: 17, 91: 16, 92: 15, 93: 5, 94: 23, 95: 11, 96: 13, 97: 12, 98: 9, 99: 9, 100: 5, 101: 8, 102: 28, 103: 22, 104: 35, 105: 45, 106: 48, 107: 43, 108: 13, 109: 31, 110: 7, 111: 10, 112: 10, 113: 9, 114: 8, 115: 18, 116: 19, 117: 2, 118: 29, 119: 176, 120: 7, 121: 8, 122: 9, 123: 4, 124: 8, 125: 5, 126: 6, 127: 5, 128: 6, 129: 8, 130: 8, 131: 
3, 132: 18, 133: 3, 134: 3, 135: 21, 136: 26, 137: 9, 138: 8, 139: 24, 140: 13, 141: 10, 142: 7, 143: 12, 144: 15, 145: 21, 146: 10, 147: 20, 148: 14, 149: 9, 150: 6}, '잠': {1: 33, 2: 22, 3: 35, 4: 27, 5: 23, 6: 35, 7: 27, 8: 36, 
9: 18, 10: 32, 11: 31, 12: 28, 13: 25, 14: 35, 15: 33, 16: 33, 17: 28, 18: 24, 19: 29, 20: 30, 21: 31, 22: 29, 23: 35, 24: 34, 25: 28, 26: 28, 27: 27, 28: 28, 29: 27, 30: 33, 31: 31}, '전': {1: 18, 2: 26, 3: 22, 4: 16, 5: 20, 6: 12, 7: 29, 8: 17, 9: 18, 10: 20, 11: 10, 12: 14}, '아': {1: 17, 2: 17, 3: 11, 4: 16, 5: 16, 6: 14, 7: 13, 8: 14}, '사': {1: 31, 2: 22, 3: 26, 4: 6, 5: 30, 6: 13, 7: 25, 8: 22, 9: 21, 10: 34, 11: 16, 12: 6, 13: 22, 14: 32, 15: 9, 16: 
14, 17: 14, 18: 7, 19: 25, 20: 6, 21: 17, 22: 25, 23: 18, 24: 23, 25: 11, 26: 21, 27: 13, 28: 29, 29: 23, 30: 33, 31: 9, 32: 20, 33: 24, 34: 17, 35: 10, 36: 22, 37: 38, 38: 22, 39: 8, 40: 31, 41: 29, 42: 25, 43: 28, 44: 28, 45: 25, 46: 13, 47: 15, 48: 22, 49: 26, 50: 11, 51: 23, 52: 15, 53: 12, 54: 17, 55: 13, 56: 12, 57: 21, 58: 14, 59: 21, 60: 22, 61: 11, 62: 12, 63: 19, 64: 12, 65: 25, 66: 24}, '렘': {1: 19, 2: 37, 3: 25, 4: 31, 5: 31, 6: 30, 7: 34, 8: 22, 9: 26, 10: 25, 11: 23, 12: 17, 13: 27, 14: 22, 15: 21, 16: 21, 17: 27, 18: 23, 19: 15, 20: 18, 21: 14, 22: 30, 23: 40, 24: 10, 25: 38, 26: 24, 27: 22, 28: 17, 29: 32, 30: 24, 31: 40, 32: 44, 33: 26, 34: 22, 35: 19, 36: 32, 37: 21, 38: 28, 39: 18, 40: 16, 41: 18, 42: 22, 43: 13, 44: 30, 45: 5, 46: 28, 47: 7, 48: 47, 49: 39, 50: 46, 51: 64, 52: 34}, '애': {1: 22, 2: 22, 3: 66, 4: 22, 5: 22}, '겔': {1: 28, 2: 10, 3: 27, 4: 17, 5: 17, 6: 14, 7: 27, 8: 18, 9: 11, 10: 22, 11: 25, 12: 28, 13: 23, 14: 23, 15: 8, 16: 63, 17: 24, 18: 32, 19: 14, 20: 49, 21: 32, 22: 31, 23: 49, 24: 27, 25: 17, 26: 21, 27: 36, 28: 26, 29: 21, 30: 26, 31: 18, 32: 32, 33: 33, 34: 31, 35: 15, 36: 38, 37: 28, 38: 23, 39: 29, 40: 49, 41: 26, 42: 20, 43: 27, 44: 31, 45: 25, 46: 24, 47: 23, 48: 35}, '단': {1: 21, 2: 49, 3: 30, 4: 37, 5: 31, 6: 28, 7: 28, 8: 27, 9: 27, 10: 21, 11: 45, 12: 13}, '호': {1: 11, 2: 23, 3: 5, 4: 19, 5: 15, 6: 11, 7: 16, 8: 14, 9: 17, 10: 15, 11: 12, 12: 14, 13: 16, 14: 9}, '욜': {1: 20, 2: 32, 3: 21}, '암': {1: 15, 2: 16, 3: 15, 4: 13, 5: 27, 6: 14, 7: 17, 8: 14, 9: 15}, '옵': {1: 21}, '욘': {1: 17, 2: 10, 3: 10, 4: 11}, '미': {1: 16, 2: 13, 3: 12, 4: 13, 5: 15, 6: 16, 7: 20}, '나': {1: 15, 2: 13, 3: 19}, '합': {1: 17, 2: 20, 3: 19}, '습': {1: 18, 2: 15, 3: 20}, '학': {1: 15, 2: 23}, '슥': {1: 21, 2: 13, 3: 10, 4: 14, 5: 11, 6: 15, 7: 14, 8: 23, 9: 17, 10: 12, 11: 17, 12: 14, 13: 9, 14: 21}, '말': {1: 14, 2: 17, 3: 18, 4: 6}, '마': {1: 25, 2: 23, 3: 17, 4: 25, 5: 48, 6: 34, 7: 29, 8: 34, 9: 38, 10: 42, 11: 30, 12: 50, 13: 58, 14: 36, 15: 39, 16: 28, 17: 27, 18: 35, 19: 30, 20: 34, 21: 46, 22: 46, 
23: 39, 24: 51, 25: 46, 26: 75, 27: 66, 28: 20}, '막': {1: 45, 2: 28, 3: 35, 4: 41, 5: 43, 6: 56, 7: 37, 8: 38, 9: 50, 10: 52, 11: 33, 12: 44, 13: 37, 14: 72, 15: 47, 16: 20}, '눅': {1: 80, 2: 52, 3: 38, 4: 44, 5: 39, 6: 49, 7: 50, 8: 56, 9: 62, 10: 42, 11: 54, 12: 59, 13: 35, 14: 35, 15: 32, 16: 31, 17: 37, 18: 43, 19: 48, 20: 47, 21: 38, 22: 71, 23: 56, 24: 53}, '요': {1: 51, 2: 25, 3: 36, 4: 54, 5: 47, 6: 71, 7: 53, 8: 59, 9: 41, 10: 42, 11: 57, 12: 50, 13: 38, 14: 31, 15: 27, 16: 33, 17: 26, 18: 40, 19: 42, 20: 31, 21: 25}, '행': {1: 26, 2: 47, 3: 26, 4: 37, 5: 42, 6: 15, 7: 60, 8: 40, 9: 43, 10: 48, 11: 30, 12: 25, 13: 52, 14: 28, 15: 41, 16: 40, 17: 34, 18: 28, 19: 41, 20: 38, 21: 40, 22: 30, 23: 35, 24: 27, 25: 27, 26: 32, 27: 44, 28: 31}, '롬': {1: 32, 2: 29, 3: 31, 4: 25, 5: 21, 6: 23, 7: 25, 8: 39, 9: 33, 10: 21, 11: 36, 12: 21, 13: 14, 14: 23, 15: 33, 16: 27}, '고전': {1: 31, 2: 16, 3: 23, 4: 21, 5: 
13, 6: 20, 7: 40, 8: 13, 9: 27, 10: 33, 11: 34, 12: 31, 13: 13, 14: 40, 15: 58, 16: 24}, '고후': {1: 24, 2: 17, 3: 18, 4: 18, 5: 21, 6: 18, 7: 16, 8: 24, 9: 15, 10: 18, 11: 33, 12: 21, 13: 13}, '갈': {1: 24, 2: 21, 3: 29, 4: 31, 5: 26, 6: 18}, '엡': {1: 23, 2: 22, 3: 21, 4: 32, 5: 33, 6: 24}, '빌': {1: 30, 2: 30, 3: 21, 4: 23}, '골': {1: 29, 2: 23, 3: 25, 4: 18}, '살전': {1: 10, 2: 20, 3: 13, 4: 18, 5: 28}, '살후': {1: 12, 2: 17, 3: 18}, '딤전': {1: 20, 2: 15, 3: 16, 4: 16, 5: 25, 6: 21}, '딤후': {1: 18, 2: 26, 3: 17, 4: 22}, '딛': {1: 16, 2: 15, 3: 16}, '몬': {1: 25}, '히': {1: 14, 2: 18, 3: 19, 4: 16, 5: 14, 6: 20, 7: 28, 8: 13, 9: 28, 10: 39, 11: 40, 12: 29, 13: 25}, '약': {1: 27, 
2: 26, 3: 18, 4: 17, 5: 20}, '벧전': {1: 25, 2: 25, 3: 22, 4: 19, 5: 14}, '벧후': {1: 21, 2: 22, 3: 18}, '요일': {1: 10, 2: 29, 3: 24, 4: 21, 5: 21}, '요이': {1: 13}, '요삼': {1: 15}, '유': {1: 25}, '계': {1: 20, 2: 29, 3: 22, 4: 11, 5: 14, 6: 17, 7: 17, 8: 13, 9: 21, 10: 11, 11: 19, 12: 17, 13: 18, 14: 20, 15: 8, 16: 21, 17: 18, 18: 24, 19: 21, 20: 15, 21: 27, 22: 21}}
        
        self.book_names = [
            "창세기", "출애굽기", "레위기", "민수기", "신명기", "여호수아", "사사기", "룻기",
            "사무엘상", "사무엘하", "열왕기상", "열왕기하", "역대상", "역대하", "에스라", "느헤미야",
            "에스더", "욥기", "시편", "잠언", "전도서", "아가", "이사야", "예레미야", "예레미야애가",
            "에스겔", "다니엘", "호세아", "요엘", "아모스", "오바댜", "요나", "미가", "나훔",
            "하박국", "스바냐", "학개", "스가랴", "말라기", "마태복음", "마가복음", "누가복음",
            "요한복음", "사도행전", "로마서", "고린도전서", "고린도후서", "갈라디아서", "에베소서",
            "빌립보서", "골로새서", "데살로니가전서", "데살로니가후서", "디모데전서", "디모데후서",
            "디도서", "빌레몬서", "히브리서", "야고보서", "베드로전서", "베드로후서", "요한일서",
            "요한이서", "요한삼서", "유다서", "요한계시록"
        ]

        self.book_abbreviations = [
            "창", "출", "레", "민", "신", "수", "삿", "룻", "삼상", "삼하",
            "왕상", "왕하", "대상", "대하", "스", "느", "에", "욥", "시", "잠",
            "전", "아", "사", "렘", "애", "겔", "단", "호", "욜", "암", "옵",
            "욘", "미", "나", "합", "습", "학", "슥", "말", "마", "막", "눅",
            "요", "행", "롬", "고전", "고후", "갈", "엡", "빌", "골", "살전",
            "살후", "딤전", "딤후", "딛", "몬", "히", "약", "벧전", "벧후", "요일",
            "요이", "요삼", "유", "계"
        ]
        self.root = tk.Tk()
        self.root.geometry("1024x720")
        self.root.title("Find Bible")
        
        self.label = ttk.Label(self.root, text="성경선택:")
        self.label.place(x=20, y=30)
        
        self.book_combobox = ttk.Combobox(self.root, values=list(self.chapter_verse.keys()))
        self.book_combobox.bind("<<ComboboxSelected>>", self.update_chapters)
        self.book_combobox.place(x=90, y=30)
        
        self.label_chapter = ttk.Label(self.root, text="장:")
        self.label_chapter.place(x=270, y=30)
        
        self.chapter_combobox = ttk.Combobox(self.root)
        self.chapter_combobox.bind("<<ComboboxSelected>>", self.update_verses)
        self.chapter_combobox.place(x=300, y=30)
        
        self.label_verse = ttk.Label(self.root, text="시작 끝 절:")
        self.label_verse.place(x=490, y=30)
        
        self.start_verse_combobox = ttk.Combobox(self.root)
        self.start_verse_combobox.place(x=560, y=30)

        # 에러 메시지 라벨 생성
        self.error_label = tk.Label(self.root, text="", fg="red")
        self.error_label.place(x=560, y=60)

        self.end_verse_combobox = ttk.Combobox(self.root)
        self.end_verse_combobox.place(x=740, y=30)

        # 검색 버튼
        self.extract_button = tk.Button(self.root, text="검색", command=self.extract_button_click, width=10)
        self.extract_button.place(x=920, y=30)

        self.save_button = tk.Button(self.root, text="저장", command=self.save_button_click, width=20)
        self.save_button.place(x=450, y=100)

        self.clear_button = tk.Button(self.root, text="초기화", command=self.clear_button_click, width=10)
        self.clear_button.place(x=920, y=100)

        # 결과 텍스트 박스
        self.result_text = scrolledtext.ScrolledText(self.root, width=140, height=40)
        self.result_text.place(x=0, y=150)


        self.root.mainloop()

    def update_chapters(self, event):
        selected_book = self.book_combobox.get()
        if selected_book in self.chapter_verse:
            chapters = list(self.chapter_verse[selected_book].keys())
            self.chapter_combobox['values'] = chapters

    def update_verses(self, event):
        selected_book = self.book_combobox.get()
        selected_chapter = int(self.chapter_combobox.get())
        if selected_book in self.chapter_verse and selected_chapter in self.chapter_verse[selected_book]:
            verses = list(range(1, self.chapter_verse[selected_book][selected_chapter] + 1))
            self.start_verse_combobox['values'] = verses
            self.end_verse_combobox['values'] = verses

    def extract_bible_range_from_file(self, book, chapter, start_verse, end_verse):
        result = []
        within_range = False

        for line in self.lines:
            if not start_verse:
                if f"{book}{chapter}:" in line:
                    result.append(line.strip())
                    within_range = True
                elif within_range and ':' in line:
                    within_range = False
                    break
                elif within_range:
                    result.append(line.strip())
            elif f"{book}{chapter}:{start_verse} " in line:
                within_range = True
                result.append(line.strip())

                # 한 절인 경우
                if start_verse == end_verse:
                    break
                # 마지막 절이 없는 경우
                if not end_verse:
                    break
            elif within_range:
                result.append(line.strip())
                if f"{book}{chapter}:{end_verse} " in line:
                    within_range = False
                    break
        return result

        
    def extract_button_click(self):
        book = self.book_abbreviations[self.book_combobox.current()]
        chapter = self.chapter_combobox.get()
        start_verse = self.start_verse_combobox.get()
        end_verse = self.end_verse_combobox.get()

        if end_verse and int(start_verse) > int(end_verse):
            self.error_label.config(text="시작 절이 끝 절보다 큽니다.", fg="red")
            return
        else:
            self.error_label.config(text="", fg="red")
        
        extracted = self.extract_bible_range_from_file(book, chapter, start_verse, end_verse)

        if extracted:
            for line in extracted:
                first_space_index = line.find(' ')

                if first_space_index != -1:
                    line = '[' + line[:first_space_index] + '] ' + line[first_space_index+1:]

                self.result_text.insert(tk.END, line + "\n//\n")
        else:
            messagebox.showwarning("에러", "해당 구절을 찾을 수 없습니다.")

    def save_to_desktop(self, verse):
        today = datetime.today().strftime('%Y-%m-%d')
        desktop_path = os.path.join(os.path.expanduser('~'), 'Desktop')
        file_name = f"bible_verse_{today}.txt"
        file_path = os.path.join(desktop_path, file_name)
        with open(file_path, 'w', encoding='ansi') as f:
            f.write(verse)
        return file_path

    def save_button_click(self):
        extracted_text = self.result_text.get("1.0", tk.END)
        if extracted_text.strip():
            saved_file_path = self.save_to_desktop(extracted_text)
            messagebox.showinfo("저장 완료", "파일이 저장되었습니다.")

    def clear_button_click(self):
        self.result_text.delete('1.0', tk.END)
        self.error_label.config(text="", fg="red")
        self.book_combobox.set("")
        self.chapter_combobox.set("")
        self.start_verse_combobox.set("")
        self.end_verse_combobox.set("")


if __name__ == "__main__":
    app = BibleApp()

 

코드설명

먼저 실행하게 되면 bible.txt 파일을 read하여 개행을 기반으로 절들을 잘라놓습니다.

사용자가 성경목록을 선택하면 해당되는 성경의 장을 목록으로 업데이트합니다.

장을 선택하면 절을 목록으로 업데이트합니다.

 

시작절과 끝절을 각각 선택 후 검색을 누르게 되면 해당 절을 아래 스크롤텍스트박스에 출력하게 됩니다.

출력은 GenCG 텍스트 입력에 맞게 //를 기반으로 나눴습니다.

 

결과 화면

성경찾기 화면
성경찾기 저장
성경찾기 결과 파일

 

첨부파일

bible.txt

bible.txt 파일은 C:/MC/ 폴더에 넣어주세요.

bible.txt
4.66MB

성경찾기.exe

참고: 성경찾기.exe의 결과는 바탕화면에 출력됩니다.

성경찾기.exe
9.17MB

 

 

반응형

댓글