4

I'm working on a settings menu. I'm using a ttk notebook with tabs for different categories, some categorie names are longer then the others. By default the names align to the right causing it to look like this:

Visual of what it looks like

I want them to align on the left instead of the right.

From my research I understand that you have to use style.theme_create(...) which will create a new style. This does not meet my requirements since I'm already using a theme. I would like to edit it, not create a new one.

I've tried editing the style in a few ways without success, (this is only a test code) for example:

from Tkinter import *
import ttk

root = Tk()
style = ttk.Style(root)
style.configure('lefttab.TNotebook', tabposition='wn') # wn because I want the tab to be vertical (on the side not the top)
style.configure('TNotebook.Tab', align=LEFT)
notebook = ttk.Notebook(root, style='lefttab.TNotebook')
f1 = Frame(notebook, bg='red', width=200, height=200)
f2 = Frame(notebook, bg='blue', width=200, height=200)
Label(f1, text="Test").grid(column=3, row=1, sticky=S)
notebook.add(f1, text='short')
notebook.add(f2, text='Loooooong')
notebook.pack()
root.mainloop()

The result of the code is as follows:

alignment test

My assumption is that I am not using the right parameters for style.configure(...)

Edit: Before I tried using align to solve my problem which didn't work. Now I also tried sticky and fill=X as shown in the following code:

from Tkinter import *
import ttk

myred = "#dd0202"
mygreen = "#d2ffd2"
root = Tk()
style = ttk.Style(root)
style.configure('lefttab.TNotebook', tabposition='wn')
style.configure('TNotebook', sticky=W, fill=X )
#style.configure('TNotebook.Tab', align=LEFT)
#style.configure("TNotebook", background=myred)

notebook = ttk.Notebook(root, style='lefttab.TNotebook')
f1 = Frame(notebook, bg='red', width=200, height=200)
f2 = Frame(notebook, bg='blue', width=200, height=200)
notebook.add(f1, text='short',sticky=W)
notebook.add(f2, text='Loooooong', sticky=W)
notebook.pack()
root.mainloop()

This still doesn't solve my problem. I want to align the "Label" of a tab to the left when stacked vertically.

martineau
  • 119,623
  • 25
  • 170
  • 301
Royi Levy
  • 513
  • 1
  • 3
  • 14
  • Does this answer your question? [Changing the tab sizes of a Notebook widget in Python 3](https://stackoverflow.com/questions/36024635/changing-the-tab-sizes-of-a-notebook-widget-in-python-3) – stovfl Apr 19 '20 at 14:48
  • @stovfl No, I saw this question already but it does not help me. I want to "edit" a already existing theme, not create a new one. – Royi Levy Apr 20 '20 at 15:21
  • ***I want to "edit" a already existing theme***: What is stopping you to use `TNotebook.Tab", "padding": [100, 100] ` from the linked answer? – stovfl Apr 20 '20 at 15:51
  • 1
    @stovfl how does padding help in my situation? Besides, he uses: `style.theme_create( "MyStyle", parent="alt", settings={ "TNotebook": {"configure": {"tabmargins": [2, 5, 2, 0] } }, "TNotebook.Tab": {"configure": {"padding": [100, 100] },}}) style.theme_use("MyStyle")` Where he creates a new style, then switches to use it. – Royi Levy Apr 21 '20 at 15:22

0 Answers0