Skip to main content

CTkTabview

The CTkTabview creates a tabview, similar to a notebook in tkinter. The tabs, which are created with .add("<tab-name>") are CTkFrames and can be used like CTkFrames. Any widgets can be placed on them.

Example Code

Example without using classes:

tabview = customtkinter.CTkTabview(master=app)
tabview.pack(padx=20, pady=20)

tabview.add("tab 1") # add tab at the end
tabview.add("tab 2") # add tab at the end
tabview.set("tab 2") # set currently visible tab

button = customtkinter.CTkButton(master=tabview.tab("tab 1"))
button.pack(padx=20, pady=20)

It's also possible to save tabs in extra variables:

tab_1 = tabview.add("tab 1")
tab_2 = tabview.add("tab 2")

button = customtkinter.CTkButton(tab_1)

Example with classes:

class MyTabView(customtkinter.CTkTabview):
def __init__(self, master, **kwargs):
super().__init__(master, **kwargs)

# create tabs
self.add("tab 1")
self.add("tab 2")

# add widgets on tabs
self.label = customtkinter.CTkLabel(master=self.tab("tab 1"))
self.label.grid(row=0, column=0, padx=20, pady=10)


class App(customtkinter.CTk):
def __init__(self):
super().__init__()

self.tab_view = MyTabView(master=self)
self.tab_view.grid(row=0, column=0, padx=20, pady=20)


app = App()
app.mainloop()

Arguments

argumentvalue
masterroot, frame, top-level
widthwidth in px, tabs will be slightly smaller
heightheight in px, tabs will be slightly smaller
corner_radiuscorner radius in px
border_widthborder width in px
fg_colorforeground color of the tabview itself and the tabs, tuple: (light_color, dark_color) or single color
border_colorborder color, tuple: (light_color, dark_color) or single color
segmented_button_fg_colorforeground color of segmented button, tuple: (light_color, dark_color) or single color
segmented_button_selected_colorselected color of segmented button, tuple: (light_color, dark_color) or single color
segmented_button_selected_hover_colorselected hover color of segmented button, tuple: (light_color, dark_color) or single color
segmented_button_unselected_colorunselected color of segmented button, tuple: (light_color, dark_color) or single color
segmented_button_unselected_hover_colorunselected hover color of segmented button, tuple: (light_color, dark_color) or single color
text_colortext color of segmented button, tuple: (light_color, dark_color) or single color
text_color_disabledtext color of segmented buttons when widget is disabled, tuple: (light_color, dark_color) or single color
commandfunction will be called when segmented button is clicked
anchorposition of the segmneted button, default is "n", values are "nw", "n", "ne", "sw", "s", "se"
state"normal" or "disabled"

Methods

  • .configure(attribute=value, ...)

    All attributes can be configured and updated.

  • .cget(attribute_name)

    Get values of all attributes specified as string.

  • .tab(name)

    Returns reference to tab with given name. Can be used like a frame like this:

    button = customtkinter.CTkButton(master=tabview.tab("tab name"))
  • .insert(index, name)

    Insert tab with name at position of index, name must be unique.

  • .add(name)

    Add tab with name at the end, name must be unique.

  • .index(name)

    Get index of tab with given name.

  • .move(new_index, name)

    Move tab with name to given index.

  • .rename(old_name, new_name)

    Rename tab.

  • .delete(name)

    Delete tab with name.

  • .set(name)

    Set tab with name to be visible.

  • .get()

    Get name of tab that's currently visible.