PyTermGUI
A lightweight and high-performance TUI library for Python. Provides YAML-based configuration, customizable themes, and rich widgets.
GitHub Overview
bczsalba/pytermgui
Python TUI framework with mouse support, modular widget system, customizable and rapid terminal markup language and more!
Repository:https://github.com/bczsalba/pytermgui
Homepage:https://ptg.bczsalba.com
Stars2,478
Watchers19
Forks62
Created:March 31, 2021
Language:Python
License:MIT License
Topics
ansiansi-escape-codesansi-escape-sequencesclicommand-lineconsolecross-platformguipytermguipythonpython3terminaltuityping
Star History
Data as of: 7/25/2025, 06:23 AM
PyTermGUI
PyTermGUI is a lightweight and high-performance library for building TUI applications in Python. It features a YAML-based configuration system and customizable theme engine, providing a rich set of widgets.
Key Features
YAML-Based Configuration
- Configuration Management: Manage application settings with YAML files
- Theme System: Define colors and styles in YAML
- Flexible Structure: Express complex layouts in configuration files
Rich Widget Set
- Basic Widgets: Buttons, labels, input fields
- Layouts: Containers, splitters, tabs
- Advanced Components: Menus, dialogs, progress bars
High Performance
- Optimized Rendering: Efficient screen updates
- Memory Efficient: Lightweight memory footprint
- Responsive: Smooth user interactions
Installation
pip install pytermgui
Basic Usage
Simple Application
import pytermgui as ptg
def main():
with ptg.WindowManager() as manager:
window = ptg.Window(
"Hello PyTermGUI!",
ptg.Button("Click me!", lambda *_: print("Button clicked!")),
ptg.Button("Quit", lambda *_: manager.stop()),
)
manager.add(window)
if __name__ == "__main__":
main()
Using Widgets
import pytermgui as ptg
def create_form():
# Create input form
form = ptg.Container(
ptg.Label("User Information"),
ptg.InputField(prompt="Name: "),
ptg.InputField(prompt="Email: "),
ptg.Button("Submit", on_click=submit_form),
)
return form
def submit_form(button):
# Form submission handling
print("Form submitted!")
with ptg.WindowManager() as manager:
window = ptg.Window(create_form())
manager.add(window)
YAML Theme Configuration
# theme.yaml
colors:
primary: "#3498db"
secondary: "#2ecc71"
background: "#2c3e50"
text: "#ffffff"
widgets:
Button:
background: primary
foreground: text
border: "single"
InputField:
background: background
foreground: text
border: "double"
import pytermgui as ptg
# Load theme
ptg.load_theme("theme.yaml")
# Start application
with ptg.WindowManager() as manager:
# Themed widgets
window = ptg.Window(
ptg.Button("Themed Button"),
ptg.InputField(prompt="Themed Input: "),
)
manager.add(window)
Advanced Features
Custom Widgets
import pytermgui as ptg
class CounterWidget(ptg.Widget):
def __init__(self, initial_value=0):
super().__init__()
self.count = initial_value
self.label = ptg.Label(f"Count: {self.count}")
self.inc_button = ptg.Button("+", self.increment)
self.dec_button = ptg.Button("-", self.decrement)
self.container = ptg.Container(
self.label,
ptg.Container(self.dec_button, self.inc_button),
)
def increment(self, *_):
self.count += 1
self.label.value = f"Count: {self.count}"
def decrement(self, *_):
self.count -= 1
self.label.value = f"Count: {self.count}"
Layout Management
import pytermgui as ptg
def create_layout():
# Split layout
splitter = ptg.Splitter(
ptg.Container(
ptg.Label("Left Panel"),
ptg.Button("Button 1"),
ptg.Button("Button 2"),
),
ptg.Container(
ptg.Label("Right Panel"),
ptg.InputField(prompt="Input: "),
ptg.TextArea(placeholder="Text area..."),
),
)
return splitter
with ptg.WindowManager() as manager:
window = ptg.Window(create_layout())
manager.add(window)
Comparison with Other Libraries
Feature | PyTermGUI | Textual | Urwid |
---|---|---|---|
Configuration | YAML | Python | Python |
Themes | Rich | CSS-like | Limited |
Performance | High | High | Medium |
Learning Curve | Low | Medium | High |
Documentation | Good | Excellent | Comprehensive |
Use Cases
- Configuration Tools: TUI tools for system administration
- Development Tools: Project management and monitoring tools
- Data Entry: Form-based applications
- Games: Simple terminal games
Community and Support
- GitHub: Active development and issue management
- Documentation: Comprehensive API reference
- Examples: Rich sample code
- Community: Active discussions
PyTermGUI modernizes TUI application development with a contemporary approach, balancing high performance with ease of use.