Align tabs from right to left using ttk.Notebook widget

假如想象 提交于 2020-01-11 02:05:08

问题


I want to align tabs (panes) inside a ttk.Notebook widget from right to left (the default is from left to right). How might this be done?

Below is my current code:

import Tkinter as tk
import ttk

root = tk.Tk()
root.minsize(300, 300)
root.geometry("1000x700")

box = ttk.Notebook(root, width=1000, height=650)

tab1 = tk.Frame(root)
tab2 = tk.Frame(root)
tab3 = tk.Frame(root)

box.add(tab1, text="tab1")
box.add(tab2, text="tab2")
box.add(tab3, text="tab3")

box.pack(side=tk.TOP)

root.mainloop()

回答1:


There is actually a style option for this - tabposition.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.minsize(300, 300)
root.geometry("1000x700")

s = ttk.Style()
s.configure('TNotebook', tabposition='ne') #'ne' as in compass direction

box = ttk.Notebook(root, width=1000, height=650)

tab1 = tk.Frame(root)
tab2 = tk.Frame(root)
tab3 = tk.Frame(root)

box.add(tab1, text="tab1")
box.add(tab2, text="tab2")
box.add(tab3, text="tab3")

box.pack(side=tk.TOP)

root.mainloop()



回答2:


In Oblivion's line:

s.configure('TNotebook', tabposition='ne')

the 'ne' bit can be:

nw => above (north) and toe the left (west)
ne => above and to the right (east)
en => to the right (east), at the top
es => to the right (east), at the bottom
se => below (south) and to the right (east)
sw => below (south) and to the left (west)
ws => to the left (west) and to the bottom (south)
wn => to the left (west) and at top

'nw' is, I guess, the more common one, but an application may require it otherwise.



来源:https://stackoverflow.com/questions/20822553/align-tabs-from-right-to-left-using-ttk-notebook-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!