Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 835
Hangon Avatar asked Jan 01 '15 11:01

Hangon


1 Answers

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.

like image 141
James Kent Avatar answered Oct 09 '22 23:10

James Kent