简体   繁体   English

管理ttk.Notebook中的选项卡(启用,禁用等)

[英]Managing tabs in a ttk.Notebook (enabling, disabling, etc.)

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. 我想知道在创建ttk.Notebook后如何更改其状态,以及如何正确管理多个标签。

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. 在此示例中,我使用disable-enable,但总的来说,我希望能够一次更改某些设置。

What you call item is just an identifier (a float), which doesn't have a state key or a configure method. 您所称的item只是一个标识符(浮点数),没有state键或configure方法。 Also, the possible values for a tab's state in this context are normal , disabled and hidden , not enabled . 同样,在此上下文中,选项卡状态的可能值是normaldisabledhidden ,not enabled Try this instead: 尝试以下方法:

for i, item in enumerate(tabs): 
    notebook.tab(item, state='normal') # Does work

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM