添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more

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.

That's exactly what I want. One more question, If it's possible to change the position, is it possible to hide the tabs and use buttons? What I mean is to emulate the way the tabs work but, with icon buttons. The tabs on notebook widgets show frames in every tab, and this is what I want. Thanks! – David González Blazman Oct 24 '17 at 12:02 Sorry, I must dedicate more time to search than ask. I have found the hide option searching on the tkinter documentation. – David González Blazman Oct 24 '17 at 12:06 @j_4321 You really helped me with this. I noticed that if I change the name of the tabs (length of the tabs) that they are not aligned to the right side, but to the left side. Is there a way to fix this, so that they are aligned on the left? – Aleksandar Beat Jul 4 '18 at 16:51 @AleksandarBeat I am not sure I understand what you want. When a tab name is shorter, in the default linux theme, the tabs are align on the right side. Do you want them on the left? Are is the alignment different with the windows theme? Anyway, I don't know how to change the alignment. – j_4321 Jul 5 '18 at 9:55

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.