Finding the currently selected tab of Ttk Notebook

前端 未结 5 1426
南旧
南旧 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:26

    Getting the tageted tab in tk.Notebook it's easy all you have to do is to use the notebook object and target the index of the current tab. This can be done as follows

     # creating a notebook object
     notebook = ttk.Notebook(root, height=height, width=width, padding=20)
    
     # Adding tabs
     notebook.add(bin_tab, text="Binary Conversion")
     notebook.add(oct_tab, text="Octal Conversion")
     notebook.add(hex_tab, text="Hexadecimal Conversion")
    
     print(notebook.index("current")) # returns 0, 1, 2depending on how many tabs you have in my case i have 3 which means index from 0 to 2
    

提交回复
热议问题