Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot see all tabs in ttk.Notebook

I have some trouble with the tabs from the ttk Notebook class in python 2.7. I cannot see all the tabs I create.

I made a minimal code to view the problem:

from Tkinter import *
import ttk

root = Tk()
nb = ttk.Notebook(root, width=320, height=240)
nb.pack(fill=BOTH, expand=1)
page0 = Frame(nb)
page1 = Frame(nb)
page2 = Frame(nb)
page3 = Frame(nb)
page4 = Frame(nb)
nb.add(page0, text="0")
nb.add(page1, text="1")
nb.add(page2, text="2")
nb.add(page3, text="3")
nb.add(page4, text="4")

root.mainloop()

All I can see is

this

I tried to change the number of tabs and I noticed the size of the top tab bar changes and unless there's only one single lonely tab, I cannot see all of them, as you can see:

that

What I tried that didn't do anything:

  • Setting tabs width
  • Moving the .pack() around
  • Adding .pack() to the tabs
  • Using ttk.Frame instead of tk.Frame
  • Googling for a similar problem

What I tried that worked but isn't what I want:

  • Not using tabs (too many stuff to show)
  • Having only one tab

I'll appreciate any help, thanks!

like image 658
Morb Avatar asked Oct 30 '22 06:10

Morb


1 Answers

So I did fix your issue however, I have no idea why tk is doing this. I solved this tab over-lapping by increasing the length of the tab text. I changed this portion of your code:

nb.add(page0, text="long_name1")
nb.add(page1, text="long_name2")
nb.add(page2, text="long_name3")
nb.add(page3, text="long_name4")
nb.add(page4, text="long_name5")

Once again I don't know why tk does this! Someone that is more experienced with tk could probably tell you why.

like image 199
Dzhao Avatar answered Nov 02 '22 11:11

Dzhao