我正在尝试更改tkinter Notebook小部件中的标签大小,但我找不到任何实际更改标签宽度和高度的内容。有没有直接的方法来改变它们?还是有办法解决它?我正在使用python 3,如果它改变了什么。
答案 0 :(得分:5)
我认为你想要在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()
答案 1 :(得分:2)
我做了Pythonista建议的。它工作得很好,但它也修改了其他小部件的行为,因为主题是全局应用的。例如,“ askokcancel ”对话框中的文本(“确定”或“取消”)左对齐而不是停留在中心。我找到的最简单的方法是添加填充并且不会改变任何其他行为:
style = ttk.Style()
style.theme_settings("default", {"TNotebook.Tab": {"configure": {"padding": [30, 30]}}})
答案 2 :(得分:0)
这对我来说仍然没有用。我需要做的是:
style = ttk.Style()
current_theme =style.theme_use()
style.theme_settings(current_theme, {"TNotebook.Tab": {"configure": {"padding": [20, 5]}}})