Python Tkinter 侧边笔记本选项卡 [英] Python Tkinter side notebook tabs
问题描述
我正在重新设计在 python 中使用 tkinter 的程序的 GUI.我为这个程序使用了 ttk
小部件,但我认为,即使在 W10 上,界面也太旧了,所以我决定使用 METRO 界面或 W10 类似的 UI 更新程序的可视化界面.>
首先想到的是,W10 有一个非常漂亮和有用的左侧标签",问题是这是否是使用 ttk.notebook
小部件,改变标签的位置?
否则,我可以将按钮放在侧面,并在点击的每个按钮上加载框架小部件,但我认为这可能会使程序不断加载框架和小部件超载,而我正试图避免这种方式.
谢谢大家.
可以通过配置TNotebook
样式的tabposition
选项来改变tab的位置.
导入 tkinter 作为 tk从 tkinter 导入 ttk根 = tk.Tk()风格 = 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')笔记本.pack()root.mainloop()
这是在 linux 上使用默认主题的样子:
但是,选项卡内的文本始终是水平的.我没有 Windows,所以我不知道 W10 UI 的确切外观,但我猜您想旋转选项卡,而不仅仅是改变那里的位置,我不知道该怎么做.
I am redesigning the GUI of a program that uses tkinter in python. I used ttk
widgets for this program, but I think, even on W10, the interface is way too old so I decided to update the visual interface for the program using METRO interface or W10 alike UI.
The first thing that come in mind, is that W10 have a left-side "tabs" that are very beautiful and useful, and the question is if is that a way to using the ttk.notebook
widget, change the position of the tabs?
Otherwise, I could do buttons placed on the side and load frame widgets on every button clicked, but I think this could overload so much the program loading constantly frames and widgets, and I am trying to avoid this way.
Thanks to everyone.
It is possible to change the position of the tabs by configuring the tabposition
option of the TNotebook
style.
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()
This is how it looks like with the default theme on linux:
However, the text inside the tabs is always horizontal. I don't have Windows, so I don't know exactly how the W10 UI looks like, but I guess that you would like to rotate the tabs, not just change there position and I don't know how to do that.
这篇关于Python Tkinter 侧边笔记本选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!