Tkinter는 처음에 그 안에 위젯과 레이블을 포함하는 창이나 프레임을 만듭니다. 버튼으로 tkinter 창을 닫고 싶다고 가정해 봅시다. 버튼은 특정 작업을 수행하는 데 사용할 수 있는 UI 위젯입니다.
예
여기에서 tkinter 창을 닫는 버튼을 만들 것입니다. TCL 인터프리터를 닫고 종료하기 위해 주로 destroy()를 사용합니다. 방법.
#Import the required libraries
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Set the geometry of frame
win.geometry("600x250")
#Create a Label
Label(win, text="Press the Close Button to close the window",
font=('Helvetica bold', 11)).pack(pady=20)
#Define a function to close the window
def close_win():
win.destroy()
#Create a Button for closing the window
button= Button(win, text="Close", command=close_win)
button.pack(pady=20)
win.mainloop() 출력
위의 코드를 실행하면 창이나 프레임을 닫기 위해 실행할 수 있는 버튼이 포함된 창이 표시됩니다.

이제 "닫기" 버튼을 클릭하여 창을 닫습니다.