Python Forum
[Tkinter] Vertical Tabs Alignment in Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Vertical Tabs Alignment in Tkinter
#1
Hi there, Need some help.
I want the tabs to be aligned in the panel from the left. I have made them vertically positioned but couldn't correct it's positioning. I don't know what I am doing wrong in the code.
Here is the code and it's result.

tabs_frame = Frame(self.root, bd=4, bg="White", relief=GROOVE)
tabs_frame.place(x=0, y=27, width=1598, height=790)

style = ttk.Style(tabs_frame)
style.configure('lefttab.TNotebook', tabposition='wn')
style.configure('TNotebook.Tab', padding=(40, 15, 30, 5))
ttk.Style().configure("TNotebook", background='maroon', foreground='white')

notebook = ttk.Notebook(tabs_frame, style='lefttab.TNotebook')
notebook.pack(fill=X)

frame1 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame2 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame3 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame4 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame5 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame6 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame7 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame8 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame9 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame10 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame11 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame12 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame13 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame14 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame15 = tk.Frame(notebook, bg='white', width=1431, height=780)
frame16 = tk.Frame(notebook, bg='white', width=1431, height=780)

notebook.add(frame1, text='Select Patient')
notebook.add(frame2, text='Pregnancy Form')
notebook.add(frame3, text='Birth Form')
notebook.add(frame4, text='Admission Form')
notebook.add(frame5, text='Exam Form')
notebook.add(frame6, text='Respiratory Form')
notebook.add(frame7, text='Fluids Form')
notebook.add(frame8, text='Daily Form')
notebook.add(frame9, text='Tracking From')
notebook.add(frame10, text='Diagnosis Form')
notebook.add(frame11, text='XRay Form')
notebook.add(frame12, text='Lab1 Form')
notebook.add(frame13, text='Lab2 Form')
notebook.add(frame14, text='Discharge Form')
notebook.add(frame15, text='Summary Form')
notebook.add(frame16, text='Other Form') 
Reply
#2
working on a solution
Reply
#3
I wanted to show you an alternative to tkinter for this application.
Doing things like this in tkinter has always been a pain, specifically because of alignment issues.
I expact that if you use a constant width for each tab, you might be able to make it work.

At any rate, as for the alternative, here's a working script done with wxpython, tabs are nothing fancy (but there are lots of options),
text is oriented vertically as that is the default and I didn't spend the time to find out how to orient the text horizontally.

The main purpose is to show how easy it is to do in wxpython.

if you wish to try, you should be able to install wxpython from command line with pip install wxpython
import wx

class AddPanel(wx.Panel):
    def  __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.SetBackgroundColour("white")

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)

class NewWxSidetabNotebook(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(
            self, 
            None, 
            wx.ID_ANY, 
            "Side Tab Notebook"
        )

        tabs = []

        titles = [
            'Select Patient', 'Pregnancy Form', 'Birth Form',
            'Admission Form', 'Exam Form', 'Respiratory Form', 'Fluids Form',
            'Daily Form','Tracking From', 'Diagnosis Form', 'XRay Form',
            'Lab1 Form', 'Lab2 Form', 'Discharge Form', 'Summary Form', 
            'Other Form'
        ]

        nbpanel = wx.Panel(self)
        nb = wx.Notebook(nbpanel, style=wx.NB_LEFT)

        for n, title in enumerate(titles):
            tabs.append(AddPanel(nb))
            nb.AddPage(tabs[n], f"{title}")

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(nb, 1, wx.ALL | wx.EXPAND, 5)

        nbpanel.SetSizer(sizer)
        self.Layout()
        self.Show()


def main():
    app = wx.App(False)
    NewWxSidetabNotebook()
    app.MainLoop()


if __name__ == "__main__":
    main()
image of screen:
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Found buttonstate in tabs MacTommu 4 1,947 Sep-22-2021, 05:56 PM
Last Post: deanhystad
  TabError: inconsistent use of tabs and spaces in indentation hobbyist 3 4,844 Jun-15-2021, 10:38 PM
Last Post: davide73_italy
  [Tkinter] Need help please properly putting tabs within a PanedWindow JackMack118 2 3,306 Dec-08-2019, 03:02 PM
Last Post: balenaucigasa
  [PyQt] Drag items across tabs Alfalfa 5 4,684 Sep-01-2019, 11:58 PM
Last Post: Alfalfa
  [Tkinter] Adding space between Notebook tabs Columbo 4 4,425 Jul-10-2019, 10:46 PM
Last Post: Columbo
  Require scroll bars horizontal and vertical throughout the window tejgandhi 2 2,675 Jun-28-2019, 03:13 AM
Last Post: tejgandhi
  [Tkinter] How to get a tabs works exactly same as google chrome sarthak260 0 3,735 Mar-07-2019, 10:45 AM
Last Post: sarthak260
  [Tkinter] showing results in TKInter as Vertical List diegoctn 4 3,190 Jan-18-2019, 02:33 PM
Last Post: diegoctn
  [Tkinter] How to create multilple tabs in tkinter from different classes Rishav 5 18,173 Jul-11-2018, 11:59 AM
Last Post: CCChris91
  How to create mutiple tabs in tkinter using oops Rishav 2 6,821 Jul-12-2017, 04:43 PM
Last Post: Rishav

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020