Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Tkinter에서 focus와 focus_set 메소드의 차이점은 무엇입니까?

<시간/>

포커스는 현재 입력을 받고 있는 위젯이나 창을 참조하는 데 사용됩니다. 위젯을 사용하여 범위를 벗어나는 마우스 움직임, 포커스 잡기 및 키 입력 사용을 제한할 수 있습니다. 그러나 입력을 위해 활성화되도록 위젯에 초점을 맞추려면 focus.set()를 사용할 수 있습니다. 방법. 포커스() 때때로 focus_set()라고도 합니다. .

focus_set() 창이나 위젯이 포커스를 받을 때 위젯에 포커스를 맞춥니다.

예시

# Import the required libraries
from tkinter import *
from tkinter import ttk

# Create an instance of tkinter frame or window
win=Tk()

# Set the size of the window
win.geometry("700x350")

# Define a function to set the focus
def set_focus():
   entry.focus_set()

# Create an Entry widget
entry=Entry(win, width=35)
   entry.pack()

# Create a Button to get the focus on any widget
ttk.Button(win, text="Set Focus", command=set_focus).pack()

win.mainloop()

출력

위의 코드를 실행하면 버튼과 항목 위젯이 포함된 창이 표시됩니다. 버튼을 클릭하면 항목 위젯에 포커스가 설정됩니다.

Tkinter에서 focus와 focus_set 메소드의 차이점은 무엇입니까?