For some reason the font in my tkk notebook tab is top-aligned when running the code. I'm on macOS 10.11.6, using python 2.7. This is what it looks like:
It's a nuissance considering the otherwise solid native look of ttk.
Does anyone know how the theme/style could be tweaked to resolve this issue, or any other fix entirely?
Here is my code:
import Tkinter as tk
import ttk
win = tk.Tk()
frame = ttk.Frame()
win.title("Python GUI")
tabControl = ttk.Notebook(win)
tab1 = ttk.Frame(tabControl)
tabControl.add(tab1, text='Tab 1')
tab2 = ttk.Frame(tabControl)
tabControl.add(tab2, text="Tab2")
ttk.Label(tab1, text="Hello, this is a tab").grid(column=0, row=0)
ttk.Label(tab2, text="Hello, this is another tab").grid(column=0, row=0)
tabControl.pack(expand=0, fill="both")
win.mainloop()
解决方案
It's a bit difficult to say as I am unable to recreate the error you are experiencing. I think the best option would be to create a custom theme and then to change the layout options for your tabs
import Tkinter as tk
import ttk
win = tk.Tk()
frame = ttk.Frame()
style = ttk.Style()
style.theme_create("custom_tabs", parent="alt", settings={
"TNotebook.Tab": {
"configure": {"padding": [10, 10, 10, 10]}
}})
style.theme_use("custom_tabs")
win.title("Python GUI")
tabControl = ttk.Notebook(win)
tab1 = ttk.Frame(tabControl)
tabControl.add(tab1, text='Tab 1')
tab2 = ttk.Frame(tabControl)
tabControl.add(tab2, text="Tab2")
ttk.Label(tab1, text="Hello, this is a tab").grid(column=0, row=0)
ttk.Label(tab2, text="Hello, this is another tab").grid(column=0, row=0)
tabControl.pack(expand=0, fill="both")
win.mainloop()
Simply change the padding as you need it, the values are as follows:
[left padding, top padding, right padding, bottom padding]