이전 글에서 설치해야 하는 라이브러리에 대해 알아보았다. 이번 글에서는 프로그램 UI를 만들고, 어떤 함수들을 만들 것인지를 알아본다.
프로그램에 사용되는 라이브러리들은 다음과 같다. 이전 글에서 라이브러리를 설치했으면 아마 추가로 설치해야 하는 라이브러리는 없을 것 같은데, 설치가 안 된 라이브러리가 있으면 "pip install ~~" 명령어로 직접 설치해주면 된다.
import requests
from bs4 import BeautifulSoup
from urllib.request import urlopen
import pyautogui as pg
import pytesseract as pyt
pyt.pytesseract.tesseract_cmd = R'C:\Program Files\Tesseract-OCR\tesseract.exe'
import tkinter as tk
import tkinter.filedialog as fd
from tkinter import messagebox
from tkinter import *
import openpyxl
from openpyxl.styles import Alignment, Font, Border, Side, PatternFill
import os
import cv2
import pandas as pd
import numpy as np
import datetime
먼저 클래스를 만들고, 프로그램 제목과 크기, 배경, 폰트 등을 설정한다. 설정한 메이플스토리 폰트는 maplestory 공식 홈페이지에서 다운로드 받을 수 있다. 자신이 사용하고 싶은 font를 사용하려면 [ font = "맑은 고딕", 10 ] 이런식으로 설정해주면 된다.
library list...
class UI:
def __init__(self):
'''
제목 / 크기 / 배경 / 폰트설정
'''
self.main_window = tk.Tk()
self.main_window.title("원기... api 공개해줘")
self.main_window.geometry("801x420")
self.main_window.resizable(False, False)
label_image = tk.PhotoImage(file = './file/bg.png')
bg_label = tk.Label(self.main_window, image=label_image)
bg_label.place(x=0, y=0)
font = "메이플스토리", 12, "bold"
font2 = "메이플스토리", 9, "bold"
self.main_window.mainloop()
실행 결과는 다음과 같다. 나는 메이플스토리 공식 사이트 아트웍에서 받은 사진을 배경으로 설정했는데, 배경은 자기가 원하는거 집어넣으면 된다.
사용할 변수를 생성하고, 그 아래 프로그램을 실행하면 프로그램 실행시켰을 때의 날짜를 제목으로 하는 폴더를 생성하도록 한다.
library list...
class UI:
def __init__(self):
'''
변수 생성
'''
self.name = [] # 길드원 이름 저장
self.save_m = [] # 주간미션 저장
self.save_u = [] # 지하수로 저장
self.save_f = [] # 플래그 저장
self.master_name = [] # 길드 마스터 저장
self.guild_url = [] # 길드 url 저장
self.guild_list = [] # 길드 이름 저장
self.s_count = 11 # 스크린샷 카운트 버튼
self.date = datetime.datetime.today().strftime("%Y%m%d") # 프로그램 실행 날짜
'''
폴더 생성
'''
if os.path.isdir('./'+self.date) != 1:
os.mkdir('./'+self.date)
os.mkdir('./'+self.date +'/save')
os.mkdir('./'+self.date +'/create_image')
os.mkdir('./'+self.date +'/create_image/flag')
os.mkdir('./'+self.date +'/create_image/mission')
os.mkdir('./'+self.date +'/create_image/under')
'''
제목 / 크기 / 배경 / 폰트설정
'''
main_window and font setting
self.main_window.mainloop()
프로그램을 실행시켰을 때, 해당 위치에 폴더가 생성되는지 확인한다.
이제 버튼과 버튼을 설명하는 라벨들을 만들어준다. 참고로 라벨은 이미지에 넣어서 배경으로 한번에 출력하는 것이 훨씬 편하고 깔끔한데, 다음에 프로그램 작성할 일이 있으면 글을 작성해보겠다. 사실 말이 이렇게 장황할 뿐이지 그냥 이미지 만들 때 해당 위치에 글자 추가해서 저장하고 배경으로 쓰면 된다.
library list...
class UI:
def __init__(self):
create variable
create folder
main_window and font setting
'''
진행상황 텍스트
'''
self.label = tk.Label(text="Progress ...", font=font)
self.label.place(x=30, y=20)
self.progress = tk.Text(self.main_window, width=24, height=23)
self.progress.configure(font=("Arial", 9, "bold"))
self.progress.place(x=30, y=50)
self.text_index = 1.0
'''
스크린샷 버튼
'''
self.label_stat = tk.Label(self.main_window, text = "[1] 스크린샷 저장", font=font, bg="pink")
self.label_stat.place(x=250, y=50)
btn_stat = tk.Button(self.main_window, text="Screenshot", font=font, bg="pink", overrelief="solid", command=self.call_Screenshot, repeatdelay=1000)
btn_stat.place(x=250, y=90)
'''
주간미션, 수로, 플래그 점수 읽기 버튼
'''
self.label_create = tk.Label(self.main_window, text = "[2] 사진 분석", font=font, bg="pink")
self.label_create.place(x=410, y=50)
btn_create = tk.Button(self.main_window, text="Check", font=font, bg="pink", overrelief="solid", command=self.call_Find_location, repeatdelay=1000)
btn_create.place(x=410, y=90)
'''
파일 저장 버튼
'''
self.label_save = tk.Label(self.main_window, text = "[3] 변환결과저장", font=font, bg="pink")
self.label_save.place(x=550, y=50)
self.label_guild = tk.Label(self.main_window, text = "Guild", font=font, bg="pink")
self.label_guild.place(x=560, y=90)
self.text_guild = tk.Entry(self.main_window, width=15, textvariable=str)
self.text_guild.insert(0, '')
self.text_guild.place(x=630, y=90)
self.label_master = tk.Label(self.main_window, text = "Master", font=font, bg="pink")
self.label_master.place(x=550, y=120)
self.text_master = tk.Entry(self.main_window, width=15, textvariable=str)
self.text_master.insert(0, '')
self.text_master.place(x=630, y=120)
btn_save = tk.Button(self.main_window, text="Save excel", font=font, bg="pink", overrelief="solid", command=self.call_save_excel, repeatdelay=1000)
btn_save.place(x=550, y=160)
'''
파일 분석 버튼
'''
self.label_analysis = tk.Label(self.main_window, text = "[4] 파일분석", font=font, bg="pink")
self.label_analysis.place(x=250, y=210)
btn_analysis = tk.Button(self.main_window, text="Analysis", font=font, bg="pink", overrelief="solid", command=self.call_file_analysis, repeatdelay=1000)
btn_analysis.place(x=250, y=250)
'''
주간미션 체크박스
'''
self.missionCheckVal=IntVar()
self.missionCheckbox=Checkbutton(self.main_window,text="주간미션",font=font2, variable=self.missionCheckVal, command = self.call_check_mission)
self.missionCheckbox.place(x=250, y=300)
self.missiontext = tk.Entry(self.main_window, width=5, textvariable=str)
self.missiontext.configure(state='disabled')
self.missiontext.place(x=330, y=300)
'''
지하수로 체크박스
'''
self.underCheckVar=IntVar()
self.underCheckbox=Checkbutton(self.main_window,text="지하수로", font=font2, variable=self.underCheckVar, command = self.call_check_under)
self.underCheckbox.place(x=250, y=330)
self.undertext = tk.Entry(self.main_window, width=5, textvariable=str)
self.undertext.configure(state='disabled')
self.undertext.place(x=330, y=330)
'''
플래그 체크박스
'''
self.flagCheckVar=IntVar()
self.flagCheckbox=Checkbutton(self.main_window, text="플 래 그", font=font2, variable=self.flagCheckVar, command = self.call_check_flag)
self.flagCheckbox.place(x=250, y=360)
self.flagtext = tk.Entry(self.main_window, width=5, textvariable=str)
self.flagtext.configure(state='disabled')
self.flagtext.place(x=330, y=360)
'''
종료 버튼
'''
self.label_exit = tk.Label(self.main_window, text = "[5] 종료", font=font, bg="pink")
self.label_exit.place(x=410, y=210)
close_window = tk.Button(self.main_window, text="Exit", font=font, bg="pink", overrelief="solid", command=self.exit, repeatdelay=1000)
close_window.place(x=410, y=250)
self.main_window.mainloop()
그 다음에 이런식으로 각 버튼들에서 호출할 함수들의 원형을 작성한다.
library list
class UI:
def __init__(self):
create variable
create folder
main_window and font setting
text area
screenshot button
score read button
file save button
file analysis button
checkbox
exit button
self.main_window.mainloop()
'''
체크박스 체크되었는지 여부 검사하는 함수
'''
def call_check_mission(self):
self.main_window.destroy()
def call_check_under(self):
self.main_window.destroy()
def call_check_flag(self):
self.main_window.destroy()
'''
버튼 누르면 스크린샷 찍음
'''
def call_Screenshot(self):
self.main_window.destroy()
'''
길드원 참여 현황 사진에서 주간미션 / 지하수로 / 플래그레이스 점수를 읽어옴
'''
def call_Find_location(self):
self.main_window.destroy()
'''
길드 이름과 길드 마스터 닉네임으로 길드 검색
'''
def parse_maple_guild(self, guild, master):
self.main_window.destroy()
'''
검색한 길드의 길드원 닉네임 리스트 오름차순으로 가져옴
'''
def parse_guild_list(self):
self.main_window.destroy()
'''
정리한 파일을 저장함
'''
def call_save_excel(self):
self.main_window.destroy()
'''
정리한 파일을 분석함
'''
def call_file_analysis(self):
self.main_window.destroy()
'''
종료버튼
'''
def exit(self):
self.main_window.destroy()
여기까지 작성하고 프로그램을 실행하면 사진과 같이 라벨과 버튼들이 올라간다. 굉장히 조잡하지만, 우리는 디자이너가 아니니까... 예쁘게 작성할 수 있다는 건 프로그램을 만들 수 있다는 전제를 두고 말하는 거니까 만들 수 있기만 하면 언제든지 예쁘게 만들 수 있다! 는 변명을. 나중에 프로그램을 작성할 일이 있으면 따로 글을 작성해보겠다.
다음 글부터는 각 함수들을 어떻게 작성했고, 무슨 알고리즘으로 작동하는지 알아본다.
'공부 > python' 카테고리의 다른 글
[Pytesseract를 사용한 메이플스토리 길드 스코어 분석] tesseract를 사용해서 이미지에서 문자 인식하기 (0) | 2022.03.30 |
---|---|
[Pytesseract를 사용한 메이플스토리 길드 스코어 분석] 전체화면 스크린샷 찍고 스크린샷 일부분만 저장하기 (0) | 2022.03.29 |
[Pytesseract를 사용한 메이플스토리 길드 스코어 분석] 필요한 라이브러리 설치 (0) | 2022.03.27 |
[Pytesseract를 사용한 메이플스토리 길드 스코어 분석] 프로그램 소개 (0) | 2022.03.24 |
[공공 데이터 파싱 프로그램 만들기] pyinstaller로 .exe파일 생성 (0) | 2022.01.08 |
댓글