我有一个 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/