DearPyGui extension to make it easy to navigate between screens
Project description
dearpygui-router
A router library for DearPyGui, designed to make screen navigation and multi-view applications easier to build and manage — with minimal boilerplate.
Inspired by the way DPG uses context managers (with blocks), this router library introduces a stack-based, nested routing system that supports:
- Multiple screens
- Nested routers
- Declarative layout
🚀 Installation
pip install dearpygui-router
Motivation
Managing multiple "screens" in DearPyGui typically requires manually hiding/showing groups or rebuilding the UI on each view switch. dearpygui-router simplifies this by letting you declare a route hierarchy that can be navigated like a state machine.
Features
- ✅ Simple navigation:
navigate("route") - ✅ Nested routers:
navigate("parent/child/screen") - ✅ Screens as reusable classes or functions
- ✅ Familiar DPG-style API: with
dpgr.router(), withdpgr.screen()
Basic Usage
dearpygui-router has a a few different ways to setup a Router and Screens
Declarative Screens
import dearpygui.dearpygui as dpg
import dearpygui_router as dpgr
dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()
with dpg.window(tag="_main_window", label="Router Demo"):
# Nav Buttons
with dpg.group(horizontal=True):
dpg.add_button(label="Go To 1", callback=lambda: dpgr.navigate("screen1"))
dpg.add_button(label="Go To 2", callback=lambda: dpgr.navigate("screen2"))
# Router with two screens
with dpgr.router(tag="main"):
with dpgr.screen(route_name="screen1", is_initial=True):
dpg.add_text("This is screen 1")
with dpgr.screen(route_name="screen2"):
dpg.add_text("This is screen 2")
dpg.show_viewport()
dpg.set_primary_window("_main_window", True)
dpg.start_dearpygui()
dpg.destroy_context()
Function Screens
import dearpygui.dearpygui as dpg
from dearpygui_router import Router
def screen1():
dpg.add_text("Screen 1")
dpg.add_button(label="Go To 2", callback=lambda: router.navigate("screen2"))
def screen2():
dpg.add_text("Screen 2")
dpg.add_button(label="Go To 1", callback=lambda: router.navigate("screen1"))
dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()
# Create router
router = Router("top")
router.register_screen_function("screen1", screen1, is_initial=True)
router.register_screen_function("screen2", screen2)
with dpg.window(tag="_main_window", label="Router Demo"):
# Nav Buttons
with dpg.group(horizontal=True):
dpg.add_button(label="Go To 1", callback=lambda: router.navigate("screen1"))
dpg.add_button(label="Go To 2", callback=lambda: router.navigate("screen2"))
# Add router to window
router.add_to_context()
dpg.show_viewport()
dpg.set_primary_window("_main_window", True)
dpg.start_dearpygui()
dpg.destroy_context()
Class Screens
import dearpygui.dearpygui as dpg
from dearpygui_router import Router
class Screen1:
def add_to_context(self):
dpg.add_text("Screen 1")
dpg.add_button(label="Go To 2", callback=lambda: router.navigate("screen2"))
class Screen2:
def add_to_context(self):
dpg.add_text("Screen 2")
dpg.add_button(label="Go To 1", callback=lambda: router.navigate("screen1"))
dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()
# Create router
router = Router("top")
router.register_screen_object("screen1", Screen1(), is_initial=True)
router.register_screen_object("screen2", Screen2())
with dpg.window(tag="_main_window", label="Router Demo"):
# Nav Buttons
with dpg.group(horizontal=True):
dpg.add_button(label="Go To 1", callback=lambda: router.navigate("screen1"))
dpg.add_button(label="Go To 2", callback=lambda: router.navigate("screen2"))
# Add router to window
router.add_to_context()
dpg.show_viewport()
dpg.set_primary_window("_main_window", True)
dpg.start_dearpygui()
dpg.destroy_context()
API Overview
dpgr.router(tag: Optional[str])
Creates a router context. All screens defined inside belong to this router.
dpgr.screen(tag: str)
Declares a screen (rendered as a dpg.group). Everything inside is shown/hidden together based on navigation route
dpgr.navigate(path: str)
Switches to the screen at the specified path.
Nested routes use / to separate levels (e.g., "settings/audio").
Router Protocol
dpgr.Router(name: str) Create a router instance
register(self, route_name: str, screen: ScreenHandler, is_initial=False)register_screen_function(self, route_name: str, fn: Callable, is_initial=False)register_screen_object(self, route_name: str, obj: Screen, is_initial=False)register_screen_item(self, route_name: str, item_tag: Tag, is_initial=False)register_screen_factory(self, route_name: str, factory: Callable, is_initial=False)navigate(self, route_name: str) -> Nonehome(self)Go back to the initial screen, if one was set.add_to_context(self) -> NoneAdd this router to the current DPG context. A dpg.child_window will be added.add_nested(self, router: "RouterProtocol") -> NoneAdd a nestedRouterinstance.
Roadmap
- Optional back stack
- Navigation history
- Lifecycle management
- Route Parameters
License
MIT License. See LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dearpygui_router-0.1.0.tar.gz.
File metadata
- Download URL: dearpygui_router-0.1.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34447c6f50ccfc38838252822fe06f59708775e8090e9a0e9456382b2c53df5e
|
|
| MD5 |
c981cbee40ba16dae9b1612457b0cc90
|
|
| BLAKE2b-256 |
514914790158dbef5ce7b11f9c6043ed68b62f0110148d1d3fe588cff95a8baa
|
Provenance
The following attestation bundles were made for dearpygui_router-0.1.0.tar.gz:
Publisher:
publish.yml on notbadjon/dearpygui-router
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dearpygui_router-0.1.0.tar.gz -
Subject digest:
34447c6f50ccfc38838252822fe06f59708775e8090e9a0e9456382b2c53df5e - Sigstore transparency entry: 437228805
- Sigstore integration time:
-
Permalink:
notbadjon/dearpygui-router@ea8d5b4083cdda2faf45ba7671305209eb3ca1a5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/notbadjon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea8d5b4083cdda2faf45ba7671305209eb3ca1a5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dearpygui_router-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dearpygui_router-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b7b784c02cc20852cfcd5f02fe6f2ba3b811a853ff76f094b2792ab88240bb5
|
|
| MD5 |
55afbd3ff3cd2bd53bd9c7932b000da8
|
|
| BLAKE2b-256 |
f8db69ceee441c52a22030882f2da2c9153a71b3111afd3a45216f84f96ad97a
|
Provenance
The following attestation bundles were made for dearpygui_router-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on notbadjon/dearpygui-router
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dearpygui_router-0.1.0-py3-none-any.whl -
Subject digest:
2b7b784c02cc20852cfcd5f02fe6f2ba3b811a853ff76f094b2792ab88240bb5 - Sigstore transparency entry: 437228827
- Sigstore integration time:
-
Permalink:
notbadjon/dearpygui-router@ea8d5b4083cdda2faf45ba7671305209eb3ca1a5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/notbadjon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea8d5b4083cdda2faf45ba7671305209eb3ca1a5 -
Trigger Event:
release
-
Statement type: