使用ttk.Notebook小部件从右到左对齐标签

时间:2013-12-29 05:48:46

标签: python python-2.7 tkinter ttk

我想从右到左对齐ttk.Notebook小部件中的标签(窗格)(默认是从左到右)。怎么可能这样做?

以下是我目前的代码:

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()

2 个答案:

答案 0 :(得分:10)

实际上有一个样式选项 - 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()

答案 1 :(得分:0)

在遗忘行中:

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

“ ne”位可以是:

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'是更常见的,但是应用程序可能会另外要求它。