Python Forum

Full Version: Vertical Tabs Alignment in Tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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') 
working on a solution
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:
[attachment=1004]