【问题标题】:Changing the tab sizes of a Notebook widget更改笔记本小部件的选项卡大小
【发布时间】:2016-07-01 16:20:46
【问题描述】:

我正在尝试更改 tkinter Notebook 小部件中选项卡的大小,但我无法找到任何实际更改选项卡宽度和高度的内容。没有直接的方法来改变它们吗?或者有什么办法可以绕过它?如果有任何改变,我目前正在使用 python 3。

【问题讨论】:

  • 您无法设置标签宽度。但是,您可以使用空格调整选项卡文本以获得宽度。
  • 是的,我想这可能适用于宽度。不过还是有身高问题。我想改变文本的大小可能会调整标签大小,但我不确定如何去做。

标签: python tkinter


【解决方案1】:

我想你想在 ttk 笔记本的标签页中进行填充?

在这种情况下,您可以使用自定义样式,您可以根据自己的喜好调整颜色填充等。

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
style = ttk.Style()
style.theme_create( "MyStyle", parent="alt", settings={
        "TNotebook": {"configure": {"tabmargins": [2, 5, 2, 0] } },
        "TNotebook.Tab": {"configure": {"padding": [100, 100] },}})

style.theme_use("MyStyle")

a_notebook = ttk.Notebook(root, width=200, height=200)
a_tab = ttk.Frame(a_notebook)
a_notebook.add(a_tab, text = 'This is the first tab')
another_tab = ttk.Frame(a_notebook)
a_notebook.add(another_tab, text = 'This is another tab')
a_notebook.pack(expand=True, fill=tk.BOTH)

tk.Button(root, text='Some Text!').pack(fill=tk.X)

root.mainloop()

【讨论】:

  • 是的!这正是我想要的!非常感谢。
【解决方案2】:

我按照 Pythonista 的建议做了。它工作得很好,但它也修改了其他小部件的行为,因为主题是全局应用的。例如,“askokcancel”对话框中的文本(确定或取消)左对齐而不是居中。我发现只添加填充而不改变任何其他行为的最简单方法是:

style = ttk.Style()
style.theme_settings("default", {"TNotebook.Tab": {"configure": {"padding": [30, 30]}}})

【讨论】:

    【解决方案3】:

    这仍然对我不起作用。我需要做的是:

    style = ttk.Style()                     
    current_theme =style.theme_use()
    style.theme_settings(current_theme, {"TNotebook.Tab": {"configure": {"padding": [20, 5]}}})  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 2017-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多