【问题标题】:Align tabs from right to left using ttk.Notebook widget使用 ttk.Notebook 小部件从右到左对齐选项卡
【发布时间】:2014-01-16 08:03:48
【问题描述】:

我想将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()

【问题讨论】:

  • 澄清一下,您希望标签“tab1”、“tab2”和“tab3”按此顺序出现,但在右上角?

标签: python python-2.7 tkinter ttk


【解决方案1】:

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

【讨论】:

  • 谢谢你......我认为没有办法这样做,因为我搜索了几天来解决这个问题没有运气......直到你回答了这个问题......
  • 任何寻找全宽标签对齐中心的人,使用tabposition=tk.NSEW
【解决方案2】:

Oblivion 的台词:

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

“ne”位可以是:

nw => above (north) and to 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'是更常见的一个,但应用程序可能需要它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 2013-06-11
    • 2015-02-19
    • 1970-01-01
    相关资源
    最近更新 更多