Skip to main content
 首页 » 编程设计

python之更改笔记本小部件的选项卡大小

2025年05月04日9linjiqin

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

请您参考如下方法:

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