Python Tkinter笔记本侧面选项卡

Python Tkinter side notebook tabs

我正在重新设计在python中使用tkinter的程序的GUI。 我为此程序使用了ttk小部件,但我认为,即使在W10上,该界面也太旧了,因此我决定使用METRO界面或类似W10的UI更新该程序的视觉界面。

首先想到的是W10的左侧"标签"非常漂亮且有用,问题是使用ttk.notebook小部件的方式是否可以改变标签的位置?

否则,我可以在侧面放置按钮,并在每次单击的按钮上加载框架小部件,但是我认为这可能会导致程序不断加载框架和小部件,从而使程序过载,因此,我尝试避免这种方式。

谢谢大家。


通过配置TNotebook样式的tabposition选项,可以更改选项卡的位置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import tkinter as tk
from tkinter import ttk

root = tk.Tk()

style = ttk.Style(root)
style.configure('lefttab.TNotebook', tabposition='ws')

notebook = ttk.Notebook(root, style='lefttab.TNotebook')
f1 = tk.Frame(notebook, bg='red', width=200, height=200)
f2 = tk.Frame(notebook, bg='blue', width=200, height=200)
notebook.add(f1, text='Frame 1')
notebook.add(f2, text='Frame 2')
notebook.pack()

root.mainloop()

这是Linux上默认主题的外观:

enter image description here

但是,选项卡内的文本始终是水平的。 我没有Windows,所以我不完全知道W10 UI的外观,但是我想您想旋转标签页,而不仅是更改那里的位置,我也不知道该怎么做。