5

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.

1 Answers1

14

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:

enter image description here

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.

j_4321
  • 15,431
  • 3
  • 34
  • 61
  • 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 04 '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 05 '18 at 09:55
  • Hello, is that possible set position to the notebook tab without ttk.Style ? – Acamori Mar 18 '20 at 14:08
  • @Acamori no, the notebook is a ttk widget so most of its options are set up using ttk.Style. If you don't want to use a style, you will need to create your own notebook from buttons and frames for instance. – j_4321 Mar 18 '20 at 16:19
  • @j_4321 oh... that sounds like a lot scope of work :( Ty for answer. – Acamori Mar 19 '20 at 06:21