[英]How to change the tab of ttk.Notebook
我有一個ttk.Notebook
和一個按鈕,我想切換到另一個選項卡。
我怎樣才能做到這一點?
看起來更改選項卡狀態( normal
、 disabled
和hidden
)不會解決我的問題,因為我不想禁用任何選項卡。
這是我的代碼:
import time
import ttk as ttk
import Tkinter as tk
root=tk.Tk()
root.config(width=300,height=220)
notebook=ttk.Notebook(root)
notebook.place(x=0,y=0)
tabList=[]
i=0
while i<6:
tabList.append(tk.Frame(root))
tabList[i].config(width=300,height=150,background='white')
i+=1
i=0
while i<6:
notebook.add(tabList[i],text='tab'+str(i))
i+=1
def fLoopTabs():
i=0
while i<6:
notebook.select(i)
time.sleep(2)
#Here goes the Screenshot function
i+=1
button=ttk.Button(root,text='Loop',command=fLoopTabs)
button.place(x=20,y=180)
root.mainloop()
請參閱以下鏈接:
Python Docs如果你看到 select 方法應該做你所追求的,所以是這樣的:
notebook.select(tab_id)
其中選項卡 ID 可以采用多種形式(參見第 24.2.5.3 節),但最有用的是整數(我認為這是類似於列表使用索引的索引)或您希望切換到的選項卡的名稱.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.