简体   繁体   English

Python Tkinter 侧边笔记本选项卡

[英]Python Tkinter side notebook tabs

I am redesigning the GUI of a program that uses tkinter in python.我正在重新设计在 python 中使用 tkinter 的程序的 GUI。 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.我为这个程序使用了ttk小部件,但我认为,即使在 W10 上,界面也太旧了,所以我决定使用 METRO 界面或 W10 类似的 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?首先想到的是,W10 有一个非常漂亮和有用的左侧“标签”,问题是这是否是使用ttk.notebook小部件的一种方式,可以更改标签的位置?

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.可以通过配置TNotebook样式的tabposition选项来改变tab的位置。

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:这是 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.我没有 Windows,所以我不知道 W10 UI 的确切外观,但我猜您想旋转选项卡,而不仅仅是改变那里的位置,我不知道该怎么做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM