我想知道如何在 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()
在此示例中,我使用禁用 - 启用,但通常我希望能够一次更改某些设置。