tkinter를 사용하여 응용 프로그램을 만드는 것은 쉽지만 제목 표시줄에 있는 버튼을 통해 창이나 프레임을 닫지 않고 창이나 프레임을 닫기가 어려울 때가 있습니다. 이러한 경우 .destroy()를 사용할 수 있습니다. 창을 닫는 방법입니다.
tkinter 속성은 서로 독립적이므로 버튼을 사용하여 창을 닫는 별도의 메서드를 만들 수 있습니다.
예시
#Import the library
from tkinter import *
#Create an instance of window
win = Tk()
#Set the geometry of the window
win.geometry("700x400")
#Define a function to close the window
def close_win():
win.destroy()
#Create a label
Label(win, text="Click the button to Close the window",
font=('Poppins bold', 25)).pack(pady= 20)
#Create a Button
Button(win, text= "Close", font=('Poppins bold', 16),
command=close_win).pack(pady=20)
win.mainloop() 출력
위의 코드를 실행하면 다음과 같은 출력 창이 생성됩니다 -
