Free Python Course TKinter Tabs

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

# !

"

Home and Learn - Python

TKinter Form Tabs


Section Thirteen: 1 2 3 4 5 6 7 8

Alibaba.com O!cial Website


Alibaba.com

gtx 1080 ti
57,985 FCFA Visit Site

Tabs are called Notebooks in the Tkinter


ttk library. The idea is that you set up a
parent Notebook and then add tabs to that
Notebook.

In yiour code from the previous lesson,


add the following line just after your
geometry line and before mainloop:

tab_parent = ttk.Notebook(form)

In between the round brackets of


Notebook, you need the name of a widget
that the notebook is going on. For us,
that's the main form. Our Notebook object
is being held in a variable we've called
tab_parent.

To set up a tab for your notebook, you


create Form objects with the name of a
Notebook between round brackets. Add
these two lines:

tab1 = ttk.Frame(tab_parent)
tab2 = ttk.Frame(tab_parent)

This sets up two tab objects called tab1


and tab2. We now need to add them to the
tab parent:

tab_parent.add(tab1, text="All
Records")
tab_parent.add(tab2, text="Add
New Record")

We're now using the add method of


tab_parent. In between the round rackets
of add, you need the name of the tab
object you want to add. After a comma,
we've added some text for the tab.

Finally, you need to pack the tab parent


and its tabs:

tab_parent.pack(expand=1,
!ll='both')

The expand and !ll option between pack


ensure that the tabs !ll the entire form.
Your code should look like this:

Run your program again. You should now


!nd that your form looks like this:

You can click your Add New Record tab to


activate it. You won't see much di"erence
as we haven't added any widgets to them.
Let's do that now.

Online Python Courses

Coursary Open

Adding Widgets to a Tab >

You might also like