如何在 Tkinter 應用程式中設定選項卡順序?
任何應用程式中的選項卡順序決定了該應用程式的哪個元素必須設定焦點。在 Tkinter 應用程式中,它會不斷查詢下一個需要聚焦的小部件。若要設定應用程式中的選項卡順序,我們可以定義一個函式,選擇所有小部件並使用 lift() 方法。該方法將允許該函式按程式設計方式在特定小部件上設定焦點。
示例
#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 小部件和一個可更改每個小部件的選項卡順序的按鈕。

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP