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:
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:
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.