Skip to main content

Lightweight navigation wrapper for Tkinter

Project description


Lightweight navigation wrapper for Tkinter.


pip install tkinter-nav


Create Some Pages

import tkinter as tk
import tkinter_nav as tknav

class PageOne(tknav.Page):

    def __init__(self, parent):
        tknav.Page.__init__(self, parent, 'name_of_page')

        # Use as any Frame
        # Page extends tk.Frame
        tk.Button(self, ...).pack()

    def page_did_mount(self):

    def page_did_unmount(self):

class PageTwo(tknav.Page):

class PageThree(tknav.Page):

Create your App


class App(tknav.Wrapper):

  def __init__(self):
    # Your pages
    pages = [PageOne, PageTwo]

    tknav.Wrapper.__init__(self, pages)

    # Use as any Tk instance
    # tknav.Wrapper extends tk.Tk
    self.title('My Nav App')

    # Set inital state, not required
    self.app_state = {'foo': 'bar'}

    # Show page

# Run
if __main__ == '__main__':


Navigate Between Pages

  • From the constructor
class PageOne(tknav.Page):

    def __init__(self, parent):

          command=lambda: self.navigate('page_two')
  • From a handler function
class PageOne(tknav.Page):

    def handleClick(self):

Mount and Unmount

  • page_did_mount: When the page is shown
  • page_did_unmount: When the page is hidden

Note: You do not have to use them. They will be defined with a <u>pass</u> statement.

class SomePage(tknav.Page):

    def page_did_mount(self):
      print('Page did mount')

    def page_did_unmount(self):
      print('Page did unmount')

Note: If you are familiar with React, they share the same role as ComponentDidMount and ComponentDidUnmount.


You can set a global state for your app which will enable you to share data between pages.

class App(tknav.Nav):

  def __init__(self):

    self.app_state = {'foo': 'bar'}

class PageOne(tknav.Page):

    def function(self):
      # get a value
      print(self.app_state['foo']) #bar

      # set a new value
      self.app_state['bar'] = 'foo'

When navigate() is called, the local state is merged with the global state.

class PageTwo(tknav.Page):

    def function(self):
      print(self.app_state['bar']) #foo

Note: If you are familiar with React, same principle.


Is this example, we navigated from page_one to page_two to page_one again. The state is printed in page_did_mount() and changed in page_did_unmount().

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tkinter-nav, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size tkinter_nav-0.0.3-py3-none-any.whl (8.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size tkinter-nav-0.0.3.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page