Skip to main content

Simple navigation API for tkinter

Project description

TKNav

Tknav (short for tkinter navigation) offers a simple API for you to manage navigation in your tkinter projects.

To use tknav, install the package from the pypi repository using the command

pip install tknav

In your tkinter project, import the navigator object and create an instance of it.

import Navigator from tknav
from tkinter import * as tk
...
navigator = Navigator()
...

To Create a page, instance a tkinter frame and assign it to a variable. Pass in the root object as the master to the frame

my_page = Tk.frame(root)

All the widgets existing in this page must have the variable, in this case my_page as their master.

my_label = tk.Label(my_page, text="Hello world! Welcome home!", padx=10, pady=10)

my_button = tk.Button(my_page, text="I am a button", padx=10, pady=10)

Pack all the widgets in my_page. DO NOT pack the my_page frame since that will be handled by the navigator

my_label.pack()
my_button.pack()

Alternatively, you can use the place and grid functions as well to position these widgets to your liking.

my_label.grid(column=1, row=1)
my_button.place(x=20, y=15)

After placing the widgets, add the frame, in this case my_page to the navigator using the navigator.add_page() function, passing in the page name of your liking and the frame object, my_page

navigator.add_page("hello_world_page", my_page)

To navigate to a particular page, use the navigator.navigate_to() function, passing in the name of the page you want to navigate to. This should be the same name that was passed to the add_page() function.

navigator.navigate_to("hello_world_page")

This function can be called from tkinter events such as button clicks

button = Tk.Button (
  ...
  command=lambda:navigator.navigate_to("my_page")
)

The navigator.get_history() returns an array containing the navigation history. The most recent page will be at index 0, and the oldest page will be at index -1

For example, if the user visited the home page first, then the products page, come back to the home page and visit the about page, the history will look something like this:

print(navigator.get_history())
> ["about", "home", "products", "home"]

Lastly, inorder to remove a page from the navigator, use navigator.remove_page(), passing in the name of the page you want to remove

navigator.remove_page("hello_world_page")
# this will remove the hello_world_page

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

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

Source Distribution

tknav-1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tknav-1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file tknav-1.0.tar.gz.

File metadata

  • Download URL: tknav-1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for tknav-1.0.tar.gz
Algorithm Hash digest
SHA256 c924e22e8461581240bcb22bd1d06657b5a52964d4a740f1ce196ffb2f93f853
MD5 6637b33e750ba6ecbdae0cbad94a4f8a
BLAKE2b-256 c61c52c3995d72711a5a320850a3614d59b62fac52be48ec8eb74d21795ee510

See more details on using hashes here.

File details

Details for the file tknav-1.0-py3-none-any.whl.

File metadata

  • Download URL: tknav-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for tknav-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c51d7f91062170302bf832c7927e481168118c751f3ef0e1fbabf0b1b39325b
MD5 6533242b3633a75d28188676f30c8a7a
BLAKE2b-256 3de103f5c81ed5874af09b727a465c6b41bda6bee48fa3e1eb1bd1fc1d620598

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page