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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With