CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-kivymd

Set of widgets for Kivy inspired by Google's Material Design

Pending
Overview
Eval results
Files

navigation.mddocs/

Navigation Components

Navigation components that implement Material Design navigation patterns including app bars, navigation drawers, bottom navigation, tabs, and navigation rails. These components provide consistent navigation experiences across different screen sizes and device types.

Capabilities

App Bars

Top and bottom app bars that provide primary navigation and actions for screens.

class MDTopAppBar:
    """
    Material Design top app bar.
    
    Primary app bar positioned at the top of the screen containing
    title, navigation actions, and overflow menu.
    """
    title: str  # App bar title text
    anchor_title: str  # Title anchor: "left", "center", "right"
    
    # Action items
    left_action_items: list  # Left action buttons: [["icon", callback], ...]
    right_action_items: list  # Right action buttons: [["icon", callback], ...]
    
    # Visual styling
    md_bg_color: str | list  # Background color
    specific_text_color: str | list  # Title text color
    elevation: float  # App bar elevation
    
    # Navigation
    type: str  # App bar type: "top" or "bottom"
    
    def set_left_action_items(self, items: list):
        """
        Set left action items.
        
        Args:
            items (list): List of [icon, callback] pairs
        """
        
    def set_right_action_items(self, items: list):
        """
        Set right action items.
        
        Args:
            items (list): List of [icon, callback] pairs
        """

class MDBottomAppBar:
    """
    Material Design bottom app bar.
    
    App bar positioned at the bottom of the screen, often used with
    floating action buttons and navigation actions.
    """
    md_bg_color: str | list  # Background color
    elevation: float  # App bar elevation
    
    # Action items
    left_action_items: list  # Left action buttons
    right_action_items: list  # Right action buttons
    
    # FAB integration
    allow_hidden: bool  # Allow hiding on scroll

Navigation Drawer

Slide-out navigation panel for primary navigation destinations.

class MDNavigationLayout:
    """
    Navigation layout container for drawer implementations.
    
    Container that manages the relationship between content and navigation drawer.
    """
    
class MDNavigationDrawer:
    """
    Material Design navigation drawer.
    
    Slide-out panel containing navigation destinations and actions.
    """
    type: str  # Drawer type: "standard" or "modal"
    anchor: str  # Drawer anchor: "left" or "right"  
    close_on_click: bool  # Close drawer when item clicked
    state: str  # Drawer state: "close" or "open"
    
    # Visual styling
    drawer_logo: str  # Logo image source
    drawer_header_text: str  # Header text
    
    # Behavior
    enable_swiping: bool  # Enable swipe to open/close
    swipe_distance: int   # Swipe distance threshold
    swipe_edge_width: int # Edge width for swipe detection
    
    def set_state(self, state: str, animation: bool = True):
        """
        Set drawer state.
        
        Args:
            state (str): "open" or "close"
            animation (bool): Animate the transition
        """

class MDNavigationDrawerMenu:
    """
    Navigation drawer menu container.
    
    Container for organizing navigation drawer items.
    """
    spacing: str | int  # Spacing between menu items

class MDNavigationDrawerHeader:
    """
    Navigation drawer header section.
    
    Header area typically containing user info or app branding.
    """
    text: str  # Header text
    source: str  # Header image source
    
class MDNavigationDrawerLabel:
    """
    Text label for navigation drawer sections.
    
    Section divider with text label.
    """
    text: str  # Label text
    theme_text_color: str  # Text color theme
    
class MDNavigationDrawerDivider:
    """
    Visual divider for navigation drawer sections.
    
    Horizontal line divider between sections.
    """
    
class MDNavigationDrawerItem:
    """
    Navigation drawer menu item.
    
    Individual navigation item with icon, text, and action.
    """
    text: str  # Item text
    icon: str  # Item icon from md_icons
    active: bool  # Active/selected state
    
    # Visual styling
    text_color: str | list  # Text color
    icon_color: str | list  # Icon color
    selected_color: str | list  # Selected state color
    
    def on_release(self):
        """Called when item is pressed."""

Navigation Rail

Vertical navigation component for larger screens and desktop applications.

class MDNavigationRail:
    """
    Material Design navigation rail.
    
    Vertical navigation component positioned on the left side,
    suitable for larger screens and desktop applications.
    """
    type: str  # Rail type: "unselected" or "selected"
    anchor: str  # Rail anchor: "left" or "right"
    
    # Visual styling
    md_bg_color: str | list  # Background color
    elevation: float  # Rail elevation
    
    # Items
    selected_color_background: str | list  # Selected item background
    ripple_color_item: str | list  # Item ripple color
    
class MDNavigationRailItem:
    """
    Navigation rail menu item.
    
    Individual item in the navigation rail with icon and optional text.
    """
    text: str  # Item text (optional)
    icon: str  # Item icon from md_icons
    active: bool  # Active/selected state
    
    def on_release(self):
        """Called when item is pressed."""

class MDNavigationRailFabButton:
    """
    Floating action button for navigation rail.
    
    FAB integrated into the navigation rail layout.
    """
    icon: str  # FAB icon
    md_bg_color: str | list  # Background color
    
class MDNavigationRailMenuButton:
    """
    Menu button for navigation rail.
    
    Button that triggers navigation rail menu or drawer.
    """
    icon: str  # Menu icon (typically "menu")

Bottom Navigation

Bottom navigation bar for primary navigation destinations on mobile.

class MDBottomNavigation:
    """
    Material Design bottom navigation.
    
    Bottom navigation bar with multiple tabs for primary navigation
    destinations, typically used on mobile devices.
    """
    panel_color: str | list  # Background color
    selected_color_background: str | list  # Selected tab background
    text_color_active: str | list  # Active text color
    text_color_normal: str | list  # Normal text color
    
    # Behavior
    use_text: bool  # Show text labels
    previous_tab: object  # Reference to previous tab
    
    def switch_tab(self, name_tab: str):
        """
        Switch to specified tab.
        
        Args:
            name_tab (str): Name of tab to switch to
        """

class MDBottomNavigationItem:
    """
    Bottom navigation tab item.
    
    Individual tab in bottom navigation with icon, text, and content.
    """
    name: str  # Tab name (unique identifier)
    text: str  # Tab label text
    icon: str  # Tab icon from md_icons
    
    # Content
    # Add widgets to this item to display when tab is active
    
    def on_tab_press(self):
        """Called when tab is pressed."""

Tabs

Horizontal tab navigation for organizing content into sections.

class MDTabs:
    """
    Material Design tabs.
    
    Horizontal tab navigation for organizing content into different
    sections or views within the same context.
    """
    # Tab behavior
    tab_hint_x: bool  # Enable tab width hints
    tab_bar_height: str  # Tab bar height (e.g., "48dp")
    
    # Visual styling
    indicator_color: str | list  # Active tab indicator color
    text_color_normal: str | list  # Normal tab text color
    text_color_active: str | list  # Active tab text color
    
    # Scrolling
    scrollable: bool  # Enable horizontal scrolling for many tabs
    
    def add_widget(self, widget):
        """Add tab to the tabs widget."""
        
    def switch_tab(self, name_tab: str):
        """
        Switch to specified tab.
        
        Args:
            name_tab (str): Name of tab to switch to
        """

class MDTabsBase:
    """
    Base class for tab content.
    
    Base class that tab content widgets should inherit from.
    """
    text: str  # Tab title text
    icon: str  # Tab icon (optional)
    
class MDTabsLabel:
    """
    Tab label component.
    
    Text label component used within tabs.
    """
    text: str  # Label text
    tab: object  # Reference to parent tab

Usage Examples

Top App Bar with Actions

from kivymd.uix.toolbar import MDTopAppBar
from kivymd.uix.screen import MDScreen

class MainScreen(MDScreen):
    def build(self):
        # Create app bar
        app_bar = MDTopAppBar(
            title="My App",
            anchor_title="left",
            elevation=4,
            left_action_items=[["menu", self.open_nav_drawer]],
            right_action_items=[
                ["search", self.open_search],
                ["dots-vertical", self.open_menu]
            ]
        )
        
        return app_bar
    
    def open_nav_drawer(self, instance):
        """Open navigation drawer."""
        print("Opening navigation drawer")
        
    def open_search(self, instance):
        """Open search."""
        print("Opening search")
        
    def open_menu(self, instance):
        """Open overflow menu."""
        print("Opening menu")

Navigation Drawer

from kivymd.uix.navigationdrawer import (
    MDNavigationLayout, MDNavigationDrawer, MDNavigationDrawerMenu,
    MDNavigationDrawerHeader, MDNavigationDrawerItem, MDNavigationDrawerDivider
)
from kivymd.uix.screen import MDScreen

class MainScreen(MDScreen):
    def build(self):
        # Create navigation layout
        nav_layout = MDNavigationLayout()
        
        # Create main content screen
        content_screen = MDScreen()
        
        # Create navigation drawer
        nav_drawer = MDNavigationDrawer(
            type="standard",
            close_on_click=True
        )
        
        # Create drawer menu
        menu = MDNavigationDrawerMenu()
        
        # Add header
        header = MDNavigationDrawerHeader(
            text="My App",
            source="logo.png"
        )
        menu.add_widget(header)
        
        # Add menu items
        menu_items = [
            ("home", "Home"),
            ("account", "Profile"), 
            ("settings", "Settings"),
            ("help", "Help"),
            ("logout", "Logout")
        ]
        
        for icon, text in menu_items:
            if text == "Help":
                menu.add_widget(MDNavigationDrawerDivider())
                
            item = MDNavigationDrawerItem(
                text=text,
                icon=icon,
                on_release=lambda x, item_text=text: self.nav_item_pressed(item_text)
            )
            menu.add_widget(item)
        
        nav_drawer.add_widget(menu)
        
        # Assemble layout
        nav_layout.add_widget(content_screen)
        nav_layout.add_widget(nav_drawer)
        
        return nav_layout
    
    def nav_item_pressed(self, item_text):
        """Handle navigation item press."""
        print(f"Navigation item pressed: {item_text}")

Bottom Navigation

from kivymd.uix.bottomnavigation import MDBottomNavigation, MDBottomNavigationItem
from kivymd.uix.label import MDLabel

class MainApp(MDApp):
    def build(self):
        # Create bottom navigation
        bottom_nav = MDBottomNavigation(
            panel_color="primary",
            selected_color_background="primary",
            text_color_active="white"
        )
        
        # Home tab
        home_tab = MDBottomNavigationItem(
            name="home",
            text="Home",
            icon="home"
        )
        home_tab.add_widget(MDLabel(
            text="Home Screen Content",
            halign="center"
        ))
        
        # Search tab
        search_tab = MDBottomNavigationItem(
            name="search", 
            text="Search",
            icon="magnify"
        )
        search_tab.add_widget(MDLabel(
            text="Search Screen Content",
            halign="center"
        ))
        
        # Profile tab
        profile_tab = MDBottomNavigationItem(
            name="profile",
            text="Profile", 
            icon="account"
        )
        profile_tab.add_widget(MDLabel(
            text="Profile Screen Content",
            halign="center"
        ))
        
        # Add tabs to navigation
        bottom_nav.add_widget(home_tab)
        bottom_nav.add_widget(search_tab)
        bottom_nav.add_widget(profile_tab)
        
        return bottom_nav

Tabs with Content

from kivymd.uix.tab import MDTabs, MDTabsBase
from kivymd.uix.label import MDLabel
from kivymd.uix.boxlayout import MDBoxLayout

class TabContent(MDTabsBase):
    """Custom tab content."""
    
    def __init__(self, tab_text, content_text, **kwargs):
        super().__init__(**kwargs)
        self.text = tab_text
        
        # Create content layout
        layout = MDBoxLayout(
            orientation="vertical",
            adaptive_height=True,
            spacing="16dp",
            padding="16dp"
        )
        
        # Add content
        label = MDLabel(
            text=content_text,
            theme_text_color="Primary",
            halign="center"
        )
        
        layout.add_widget(label)
        self.add_widget(layout)

class MainApp(MDApp):
    def build(self):
        # Create tabs
        tabs = MDTabs(
            tab_bar_height="48dp",
            indicator_color="primary",
            scrollable=True
        )
        
        # Add tab content
        tab_data = [
            ("Overview", "Overview content goes here"),
            ("Details", "Detailed information content"),
            ("Reviews", "User reviews and ratings"),
            ("Related", "Related items and suggestions")
        ]
        
        for tab_text, content_text in tab_data:
            tab_content = TabContent(tab_text, content_text)
            tabs.add_widget(tab_content)
        
        return tabs

Navigation Rail for Desktop

from kivymd.uix.navigationrail import (
    MDNavigationRail, MDNavigationRailItem,
    MDNavigationRailFabButton
)
from kivymd.uix.boxlayout import MDBoxLayout

class DesktopLayout(MDBoxLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.orientation = "horizontal"
        
        # Create navigation rail
        nav_rail = MDNavigationRail(
            type="selected",
            md_bg_color="primary",
            elevation=2
        )
        
        # Add FAB to rail
        fab = MDNavigationRailFabButton(
            icon="plus",
            md_bg_color="accent"
        )
        nav_rail.add_widget(fab)
        
        # Add navigation items
        nav_items = [
            ("home", "Home"),
            ("email", "Mail"),
            ("calendar", "Calendar"),
            ("folder", "Files"),
            ("settings", "Settings")
        ]
        
        for icon, text in nav_items:
            item = MDNavigationRailItem(
                text=text,
                icon=icon,
                on_release=lambda x, item_text=text: self.rail_item_pressed(item_text)
            )
            nav_rail.add_widget(item)
        
        # Content area
        content_area = MDBoxLayout(
            md_bg_color="surface",
            size_hint_x=0.8
        )
        
        # Add to main layout
        self.add_widget(nav_rail)
        self.add_widget(content_area)
    
    def rail_item_pressed(self, item_text):
        """Handle rail item press."""
        print(f"Rail item pressed: {item_text}")

Install with Tessl CLI

npx tessl i tessl/pypi-kivymd

docs

advanced.md

animations.md

application.md

buttons.md

dialogs.md

index.md

layouts.md

lists.md

navigation.md

text-input.md

tile.json