Project

[MoneyManyBank] - TKinter로 GUI 프로그램 ① 화면 설계

꼽파 2023. 12. 9. 08:49

TKinter

https://docs.python.org/3/library/tkinter.html

 

tkinter — Python interface to Tcl/Tk

Source code: Lib/tkinter/__init__.py The tkinter package (“Tk interface”) is the standard Python interface to the Tcl/Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, inclu...

docs.python.org

Python의 표준 GUI 라이브러리
TK + interface의 줄인말로, '티케이인터', '티큰터'라고 부름.
여기서 Tk는 Toolkit을 의미하며 스크립트 언어 tcl(tool command language)의 GUI 라이브러리로 개발되었음.
Tk 라이브러리를 파이썬에 연결하여 GUI 프로그래밍을 가능하게 해줌.


프로젝트 개요

사용자가 계좌를 생성하고 그 계좌로 입출금을 할 수 있는 간단한 프로그램.
그밖의 기능으로는 배경화면 색상 변경배경음악 설정관리자 모드로의 전환이 있음.

 

세부 계획

아직 기능명세서는 작성하지 않았음. 만들 계획임.

전체 GUI 완성 창/버튼 만들기, 텍스트 애니메이션 O
'고객생성' 기능 구현  class Account로 생성자  
'계좌생성' 기능 구현 가입하면 자동으로 입출금계좌 생성, 적금계좌도 생성 가능  
'고객정보조회' 기능 구현 관리자모드에서만 접근 가능함  
'거래내역조회' 기능 구현 본인 계좌의 입출금내역 확인 가능함  
'종료' 기능 구현 프로그램 종료됨 O
'언어선택' 기능 구현 한, 중, 일, 영 중 하나 선택 가능 / Google Translate API 도입 예정  
'이체한도' 기능 구현 회원 등급별 이체한도 출력 (표 형태, 출력만)  
'배경음악' 기능 구현 pygame 사용하여 배경음악 재생  
'배경색상' 기능 구현 버튼을 누르면 세 부분(왼쪽 하단, 오른쪽 하단, 메인기능 버튼)이 랜덤 색상 지정  
관리자모드로 전환 기능 구현 사용자모드에서는 톱니바퀴버튼, 관리자모드에서는 리턴버튼으로 보임.  
전체 프로그램 exe로 전환 아직 모름.  

 

 

만들게 된 계기

2개월짜리 python Aiot 수업에서 1주차에 배운 객체지향 개념을 활용하여 은행계좌를 관리하는 프로그램을 작성함.

이 프로그램은 파이참으로 실행하면 input함수로 사용자에게 번호를 입력받아, 계좌생성 및 입출금을 함.

이것을 확장하고 개선해보면 좋을 것 같아서 만들게 됨. 

 

진행소감

막상 만들고 나니까 정말 어렵다. 왜냐하면 Tkinter 사용법을 잘 몰라서 기능을 하나씩 도입할 때마다 시간 소모가 크다.

파이참에서만 실행하는 코드를 만드는 건 어렵지 않다.

그런데 tkinter를 도입하니 사용자에게 보여지는 부분까지 신경써야 해서 머릿 속이 더 복잡해진다.

버튼별로 하나씩 기능을 구현하기 시작하고 있는데, 갈 길이 멀어서 언제 끝날지 모르겠다.


  • TKinter 창 만들기
  • 창 크기 설정
  • 프레임 생성 : 프레임 vs grid
  • 환영인사 라벨 : 텍스트 애니메이션 구현, 리스트 슬라이싱, 재귀함수 vs 반복문
  • 버튼 생성 
  • 배경음악 버튼 : try-except 구문, PIL 라이브러리

"""
Tkinter 창 실행
"""
window = tk.Tk()  # 윈도우 창 생성
window.title('MoneyMany Bank')  # 제목 지정

 

###### 윈도우창 설정

# 화면의 중앙에 위치시킴
window_width = 300  # 창의 너비
window_height = 500   # 창의 높이

screen_width = window.winfo_screenwidth()  # 현재 화면 너비
screen_height = window.winfo_screenheight()  # 현재 화면 높이

x = (screen_width/2) - (window_width/2)  # x좌표
y = (screen_height/2) - (window_height/2)  # y좌표
window.geometry(f'{window_width}x{window_height}+{int(x)}+{int(y)}')  # 창의 크기와 위치를 설정
window.resizable(False, False)  # 창 크기 비활성화

'''
width x height + x + y
x와 y는 창의 왼쪽 상단 모서리의 좌표
'''

 

###### 프레임 생성

# 맨 위쪽 라벨=
top_frame = tk.Frame(window)
top_frame.pack(side="top", anchor="center", padx=2, expand=True)

# 맨 아래 왼쪽 버튼
left_bottom_frame = tk.Frame(window)
left_bottom_frame.pack(side="left", anchor="sw", pady=2, expand=True)  # sw = 남서쪽(맨 아래 왼쪽)

# 가운데 중앙 버튼
center_frame = tk.Frame(window)
center_frame.pack(side="top", anchor"center", expand=True, padx=5)  # expand=True로 창의 크기에 맞게 조정

# 맨 아래 오른쪽 버튼
right_bottom_frame = tk.Frame(window)
right_bottom_frame.pack(side="right", anchor="se", expand=True)
###### 맨 위쪽 환영 인사 라벨

# label 생성
welcome_label = tk.Label(top_frame, text='', font=("Roboto", 12))
welcome_label.pack()

# label의 텍스트 정의
welcome_text = '안녕하세요.\n머니가 마니있는\nMoneyManyBank입니다.'

# 텍스트 애니메이션 함수 호출
animate_text(welcome_text, welcome_label)
###### 버튼 생성

# 입금 버튼
dp_button = tk.Button(center_frame, text="입금", command=deposit, width=10, height=1, font=("Roboto", 20))
dp_button.pack(side="top", pady=5)

# 출금 버튼
wd_button = tk.Button(center_frame, text="출금", command=withdrawal, width=10, height=1, font=("Roboto", 20))
wd_button.pack(side="top", pady=5)

# 고객생성 버튼
c_customer_button = tk.Button(center_frame, text="고객생성", command=createCustomer, width=10, height=1, font=("Roboto", 20))
c_customer_button.pack(side="top", pady=5)

# 계좌생성 버튼
c_account_button = tk.Button(center_frame, text="계좌생성", command=createAccount, width=10, height=1, font=("Roboto", 20))
c_account_button.pack(side="top", pady=5)

# 고객정보조회 버튼
c_info_button = tk.Button(center_frame, text="고객정보조회", command=customerInformation, width=10, height=1, font=("Roboto", 20))
c_info_button.pack(side="top", pady=5)

# 거래내역조회 버튼
trans_button = tk.Button(center_frame, text="거래내역조회", command=transactionHistory, width=10, height=1, font=("Roboto", 20))
trans_button.pack(side="top", pady=5)

# 종료 버튼
exit_button = tk.Button(center_frame, text="종료", command=exit, width=10, height=1, font=("Roboto", 20))
exit_button.pack(side="top", pady=5)

# 등급별 이체한도 버튼
limit_button = tk.Button(left_bottom_frame, text="이체한도", command=transferLimit, borderwidth=10, font=("Roboto", 15))
limit_button.pack(side="bottom", pady=3)

# 언어선택 버튼
language_button = tk.Button(left_bottom_frame, text="언어선택", command=Language, borderwidth=10, font=("Roboto", 15))
language_button.pack(side="bottom", pady=3)

# 배경음악 버튼
try:
    image1 = PhotoImage(file=r"C:\PythonProjectData\MoneyManyBank\musical-note.png")
    image1 = image1.subsample(15)
    bgm_button = tk.Button(right_bottom_frame, image=image1, command=check_password)
    bgm_button.pack(side="left", pady=5, padx=3)
except Exception as e:
    print(f"Error!")

# 테마 설정 버튼
try:
    image2 = PhotoImage(file=r"C:\PythonProjectData\MoneyManyBank\theme.png")
    image2 = image2.subsample(15)
    theme_button = tk.Button(right_bottom_frame, image=image2, command=check_password)
    theme_button.pack(side="left", pady=5, padx=3)
except Exception as e:
    print(f"Error!")

# 관리자모드 전환 버튼
try:
    image3 = PhotoImage(file=r"C:\PythonProjectData\MoneyManyBank\settings.png")
    image3 = image3.subsample(15)
    admin_button = tk.Button(right_bottom_frame, image=image3, command=check_password)
    admin_button.pack(side="left", pady=5, padx=3)
except Exception as e:
    print(f"Error!")

window.mainloop()

 

텍스트 애니메이션까지 완료

 


초기에 구상한 내용

728x90