我有一个 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 节),但最有用的是整数(我认为这是类似于列表使用索引的索引)或您希望切换到的选项卡的名称.
关于python - 如何更改 ttk.Notebook 的选项卡,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27730509/