Roy*_*evy 5 python tkinter ttk
我正在研究设置菜单。我正在使用带有不同类别选项卡的 ttk 笔记本,某些类别名称比其他类别名称更长。默认情况下,名称向右对齐,使其看起来像这样:

我希望它们在左侧而不是右侧对齐。
根据我的研究,我了解到你必须使用style.theme_create(...)它来创建新的风格。这不符合我的要求,因为我已经使用了主题。我想编辑它,而不是创建一个新的。
我尝试用几种方法编辑样式但没有成功,(这只是一个测试代码)例如:
from Tkinter import *
import ttk
root = Tk()
style = ttk.Style(root)
style.configure('lefttab.TNotebook', tabposition='wn') # wn because I want the tab to be vertical (on the side not the top)
style.configure('TNotebook.Tab', align=LEFT)
notebook = ttk.Notebook(root, style='lefttab.TNotebook')
f1 = Frame(notebook, bg='red', width=200, height=200)
f2 = Frame(notebook, bg='blue', width=200, height=200)
Label(f1, text="Test").grid(column=3, row=1, sticky=S)
notebook.add(f1, text='short')
notebook.add(f2, text='Loooooong')
notebook.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
代码结果如下:

我的假设是我没有使用正确的参数style.configure(...)
编辑:
在我尝试使用它align来解决我的问题之前,它不起作用。现在我也尝试了sticky一下,fill=X如下代码所示:
from Tkinter import *
import ttk
myred = "#dd0202"
mygreen = "#d2ffd2"
root = Tk()
style = ttk.Style(root)
style.configure('lefttab.TNotebook', tabposition='wn')
style.configure('TNotebook', sticky=W, fill=X )
#style.configure('TNotebook.Tab', align=LEFT)
#style.configure("TNotebook", background=myred)
notebook = ttk.Notebook(root, style='lefttab.TNotebook')
f1 = Frame(notebook, bg='red', width=200, height=200)
f2 = Frame(notebook, bg='blue', width=200, height=200)
notebook.add(f1, text='short',sticky=W)
notebook.add(f2, text='Loooooong', sticky=W)
notebook.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
这仍然没有解决我的问题。我想在垂直堆叠时将选项卡的“标签”向左对齐。
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1110 次  |  
        
|   最近记录:  |