How can i change tab with button in tkinter?

Posted in :

在有tab 的情況下, 如果有必填的欄位使用者有少打時, 遇到錯誤要先切換到該分頁, 如果只有讓某一個控制項取得focuse 是沒用的, 需要額外讓 tab .select():

解法:
https://stackoverflow.com/questions/61691042/how-can-i-change-tab-with-button-in-tkinter

範例:

Choose a ttk.Notebook instance to use select(tab_id). In your code,Use

Tabs.select(tab2)

要讓輸入的元件focus 設使用 .focus_set():
https://stackoverflow.com/questions/70191953/is-there-a-function-to-switch-tab-and-enter-button-in-tkinter

You can bind the <Return> key event on the Entry widget. Then in the bind callback, get the next widget in the focus order by .tk_focusNext() and move focus to this widget:

import tkinter as tk

root = tk.Tk()

for i in range(10):
    e = tk.Entry(root)
    e.grid(row=0, column=i)
    e.bind('<Return>', lambda e: e.widget.tk_focusNext().focus_set())

root.mainloop()

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *