Question

I'd like to know how to change the state of a tab in a ttk.Notebook after it's creation and how to manage multiple tabs properly.

Example:

import Tkinter as tk
import ttk
from myWidgets import Widget1, Widget2, Widget3

def enableTabs(notebook):
    tabs = notebook.tabs()
    for i, item in enumerate(tabs):
        item['state'] = 'enabled' #This doesn't work
        item.configure(state='enabled') #Doesn't work either
if __name__ == '__main__':
    root = tk.Tk()

    notebook = ttk.Notebook(root)

    w1 = Widget1()
    w2 = Widget2()
    w3 = Widget3()

    notebook.add(w1, text='tab1', state='disabled')
    notebook.add(w2, text='tab2', state='disabled')
    notebook.add(w3, text='tab3', state='disabled')

    enableTabs(notebook) #This would be called upon certain events in the real     application

    root.mainloop()

In this example I use disable - enable but in general I'd like to be able to change certain settings all at once.

Was it helpful?

Solution

What you call item is just an identifier (a float), which doesn't have a state key or a configure method. Also, the possible values for a tab's state in this context are normal, disabled and hidden, not enabled. Try this instead:

for i, item in enumerate(tabs): 
    notebook.tab(item, state='normal') # Does work
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top