简体   繁体   中英

How to change the tab of ttk.Notebook

I have a ttk.Notebook and with a button I would like to switch to another tab.
How can I achieve this?

It looks that changing the tab state ( normal , disabled , and hidden ) will not solve my problem since I don't want to disable any tabs.

Here is my code:

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()

see the following link:
Python Docs if you see the select method that should do what you're after, so something like this:

notebook.select(tab_id)

where the tab id can take a number of forms (see section 24.2.5.3) but the most useful ones are an integer (i think this is the index similar to how lists use indexes) or the name of the tab you wish to switch to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM