5

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!

Morb
  • 534
  • 3
  • 14
  • 3
    This looks like a bug in ttk. If you add a space in front of or behind every label (eg: `text=" 1"` they all show up. – Bryan Oakley Mar 31 '16 at 14:45
  • 1
    @BryanOakley On Windows, it is worse. I need 6 spaces after `4` to see `4 ` on a tab the same as others. – Terry Jan Reedy Apr 01 '16 at 00:29
  • 1
    I open https://bugs.python.org/issue26682 about this issue, mostly as documentation of the bug. – Terry Jan Reedy Apr 01 '16 at 00:30
  • I'm doing this on Windows 7 Enterprise 64bit. I needed to add 4 spaces before the numbers. When I tried to do this at home, it worked with a single character (windows 7 pro 64bits). I haven't looked the exact version of python, but the one I use at work has been installed later. – Morb Apr 01 '16 at 06:20

1 Answers1

2

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.

Dzhao
  • 683
  • 1
  • 9
  • 22