Finding the currently selected tab of Ttk Notebook

前端 未结 5 1422
南旧
南旧 2021-02-07 19:58

I have a Ttk Notebook widget containing 8 Frames - so, 8 tabs. Each frame contains a Text widget. I have a button outside the Notebook widget, and I want to insert text into the

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-07 20:11

    You can retrieve the selected tab through select method. However, this method returns a tab_id which is not much useful as is. index convert it to the number of the selected tab.

    >>> nb.select()
    '.4299842480.4300630784'
    >>> nb.index(nb.select())
    2
    

    Note that you coud also get more information about the selected tab using tab

    >>> nb.tab(nb.select(), "text")
    'mytab2'
    

    You might look at Notebook reference documentation : http://docs.python.org/3/library/tkinter.ttk.html#notebook

提交回复
热议问题