모든 애플리케이션의 탭 순서는 애플리케이션의 어떤 요소가 포커스를 설정해야 하는지를 결정합니다. Tkinter 애플리케이션에서 집중해야 하는 다음 위젯을 지속적으로 찾습니다. 애플리케이션에서 탭 순서를 설정하기 위해 함수를 정의하고 모든 위젯을 선택하고 리프트() 메서드를 사용할 수 있습니다. 이를 통해 함수가 프로그래밍 방식으로 특정 위젯에 포커스를 설정할 수 있습니다.
예시
#Import the required libraries
from tkinter import *
#Create an instance of Tkinter Frame
win = Tk()
#Set the geometry of Tkinter Frame
win.geometry("700x350")
#Add entry widgets
e1 = Entry(win, width= 35, bg= '#ac12ac', fg= 'white')
e1.pack(pady=10)
e2 = Entry(win, width= 35)
e2.pack(pady=10)
e3 = Entry(win, width= 35, bg= '#aa23dd',fg= 'white')
e3.pack(pady=10)
#Change the tab order
def change_tab():
widgets = [e3,e2,e1]
for widget in widgets:
widget.lift()
#Create a button to change the tab order
Button(win, text="Change Order", font=('Helvetica 11'), command= change_tab).pack()
win.mainloop() 출력
위의 코드를 실행하면 Entry 위젯 세트와 각 위젯의 탭 순서를 변경하는 버튼이 있는 창이 표시됩니다.
