[python] Tkinter 진행 막대 바 추가

Tkinter는 Python의 표준 GUI (Graphical User Interface) 패키지입니다. 이를 사용하여 사용자 인터페이스를 만들고, 버튼, 텍스트 상자와 같은 다양한 위젯을 추가할 수 있습니다. 이번에는 Tkinter를 사용하여 진행 막대 바를 추가하는 방법에 대해 알아보겠습니다.

Tkinter에서 진행 막대 바 생성하기

Tkinter에서 진행 막대 바를 생성하기 위해서는 tkinter.ttk.Progressbar 클래스를 사용해야 합니다. 아래는 간단한 예제 코드입니다.

from tkinter import *
from tkinter.ttk import Progressbar

def start_progress():
    progress_bar.start(10)

def stop_progress():
    progress_bar.stop()

# Tkinter 윈도우 생성
window = Tk()
window.title("진행 막대 바")

# 진행 막대 바 생성
progress_bar = Progressbar(window, length=200)

# 진행 막대 바 위치 및 크기 설정
progress_bar.pack(pady=10)

# 시작 및 정지 버튼 생성
start_button = Button(window, text="시작", command=start_progress)
start_button.pack(pady=5)

stop_button = Button(window, text="정지", command=stop_progress)
stop_button.pack(pady=5)

# 윈도우 표시
window.mainloop()

위의 코드에서 length 속성은 진행 막대 바의 길이를 설정합니다. start_progress() 함수는 진행 막대 바를 시작하고, stop_progress() 함수는 진행 막대 바를 정지하는 역할을 합니다.

실행 결과 확인하기

위 코드를 실행하면 다음과 같은 결과를 확인할 수 있습니다.

진행 막대 바 예제

실행 시 “시작” 버튼을 누르면 진행 막대 바가 동작하고, “정지” 버튼을 누르면 진행 막대 바의 동작이 멈춥니다.

참고 자료