특정 Tkinter 응용 프로그램을 완벽하게 작동하고 작동하도록 만들기 위해 원하는 만큼 위젯을 사용할 수 있습니다. 위젯이 있는지 확인하려면 winfo_exists()를 사용할 수 있습니다. 방법. 확인하려는 특정 위젯으로 메서드를 호출할 수 있습니다. True(1)는 위젯이 애플리케이션에 존재함을 지정하고 False(0)은 위젯이 애플리케이션에 존재하지 않음을 지정하는 부울 값을 반환합니다.
예시
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of Tkinter Frame
win = Tk()
# Set the geometry
win.geometry("700x250")
# Define a function to check if a widget exists or not
def check_widget():
exists = label.winfo_exists()
if exists == 1:
print("The widget exists.")
else:
print("The widget does not exist.")
# Create a Label widget
label = Label(win, text="Hey There! Howdy?", font=('Helvetica 18 bold'))
label.place(relx=.5, rely=.3, anchor=CENTER)
# We will define a button to check if a widget exists or not
button = ttk.Button(win, text="Check", command=check_widget)
button.place(relx=.5, rely=.5, anchor=CENTER)
win.mainloop() 출력
위의 코드를 실행하면 버튼과 레이블 위젯이 있는 창이 표시됩니다. 애플리케이션에서 레이블 위젯이 있는지 여부를 확인할 수 있습니다.

"확인" 버튼을 클릭하면 레이블 위젯의 존재 여부를 출력합니다.
The widget exists.