我想知道如何在创建ttk.Notebook后更改选项卡的状态以及如何正确管理多个选项卡。
示例:
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()
在这个例子中,我使用了disable - enable,但一般来说我希望能够同时更改某些设置。
答案 0 :(得分:1)
您所谓的item
只是一个标识符(浮点数),它没有state
键或configure
方法。此外,此上下文中选项卡状态的可能值为normal
,disabled
和hidden
,而不是enabled
。试试这个:
for i, item in enumerate(tabs):
notebook.tab(item, state='normal') # Does work