or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

color-drawing.mdcontainer-widgets.mdcore-widgets.mddisplay-widgets.mdevent-system.mdfile-dialogs.mdindex.mdinput-widgets.mdlayouts.mdmodel-view.mdtext-editing.mdutilities.md
tile.json

tessl/pypi-pytermtk

Python Terminal Toolkit for creating sophisticated text-based user interfaces with Qt-like API and full widget support

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pytermtk@0.46.x

To install, run

npx @tessl/cli install tessl/pypi-pytermtk@0.46.0

index.mddocs/

pyTermTk

A comprehensive Text-based User Interface (TUI) library for Python that enables developers to create sophisticated terminal applications with modern UI paradigms. Evolved from pyCuT and inspired by Qt5, GTK, and tkinter APIs, pyTermTk provides a complete widget toolkit including basic widgets (buttons, labels, checkboxes) and specialized components (windows, frames, tables, trees) with a Qt-like layout system for organizing terminal interfaces.

Package Information

  • Package Name: pyTermTk
  • Language: Python
  • Installation: pip install pyTermTk
  • Minimum Python Version: 3.9+

Core Imports

import TermTk

Standard import for all widgets and functionality:

from TermTk import *

Specific imports for common components:

from TermTk import TTk, TTkWidget, TTkWindow, TTkButton, TTkLabel
from TermTk import TTkGridLayout, TTkVBoxLayout, TTkHBoxLayout
from TermTk import TTkRadioButton, TTkComboBox, TTkSpinBox, TTkListWidget

For advanced widgets from specialized modules:

from TermTk.TTkWidgets.Fancy import TTkFancyProgressBar

Basic Usage

#!/usr/bin/env python3

import sys
sys.path.append('../..')
import TermTk as ttk

# Create the main application
root = ttk.TTk()

# Create a window with title
win = ttk.TTkWindow(parent=root, pos=(1,1), size=(50,20), title="Hello World")

# Add a label
label = ttk.TTkLabel(parent=win, pos=(5, 3), text="Hello, pyTermTk!")

# Add a button
button = ttk.TTkButton(parent=win, pos=(5, 6), size=(15, 3), text="Click Me!")

# Button click handler
@ttk.pyTTkSlot()
def onButtonClick():
    label.setText("Button was clicked!")

button.clicked.connect(onButtonClick)

# Start the application
root.mainloop()

Architecture

pyTermTk follows a layered architecture inspired by Qt's design patterns:

  • TTk: Main application class managing the event loop and terminal interface
  • TTkWidget: Base class for all UI components with event handling and drawing capabilities
  • TTkContainer: Widgets that can contain other widgets with layout management
  • TTkLayout: Layout managers for automatic widget positioning (Grid, Box layouts)
  • TTkCanvas: Drawing surface with text, color, and Unicode support
  • Signal/Slot System: Event-driven communication between widgets

The library supports true color rendering, full Unicode character handling including emojis, and cross-platform compatibility across Linux, macOS, Windows, and HTML5 environments through technologies like Pyodide.

Capabilities

Core Application and Widgets

The foundational classes and widgets that form the basis of pyTermTk applications, including the main application class, base widget functionality, and essential UI components.

class TTk:
    def __init__(self, **kwargs): ...
    def mainloop(self): ...
    def quit(self): ...

class TTkWidget:
    def __init__(self, parent=None, **kwargs): ...
    def setParent(self, parent): ...
    def show(self): ...
    def hide(self): ...
    def update(self): ...

Core Application and Widgets

Layout Management

Automatic positioning and sizing of widgets using layout managers including grid layouts for complex arrangements and box layouts for linear organization.

class TTkGridLayout:
    def __init__(self): ...
    def addWidget(self, widget, row, col, rowspan=1, colspan=1): ...

class TTkVBoxLayout:
    def __init__(self): ...
    def addWidget(self, widget): ...

class TTkHBoxLayout:
    def __init__(self): ...
    def addWidget(self, widget): ...

Layout Management

Input Widgets

Interactive widgets for user input including buttons, text fields, checkboxes, combo boxes, radio buttons, sliders, spin boxes, and list widgets for comprehensive form controls.

class TTkButton:
    def __init__(self, parent=None, text="", **kwargs): ...
    clicked: pyTTkSignal

class TTkLineEdit:
    def __init__(self, parent=None, text="", **kwargs): ...
    def setText(self, text): ...
    def text(self): ...
    textChanged: pyTTkSignal

class TTkCheckbox:
    def __init__(self, parent=None, text="", **kwargs): ...
    def setChecked(self, checked): ...
    def isChecked(self): ...
    toggled: pyTTkSignal

class TTkRadioButton:
    def __init__(self, parent=None, **kwargs): ...
    def setChecked(self, checked): ...
    def isChecked(self): ...
    toggled: pyTTkSignal

class TTkComboBox:
    def __init__(self, parent=None, **kwargs): ...
    def addItem(self, text, userData=None): ...
    def currentText(self): ...
    currentIndexChanged: pyTTkSignal

class TTkSpinBox:
    def __init__(self, parent=None, **kwargs): ...
    def setValue(self, value): ...
    def value(self): ...
    valueChanged: pyTTkSignal

class TTkSlider:
    def __init__(self, parent=None, **kwargs): ...
    def setValue(self, value): ...
    def value(self): ...
    sliderMoved: pyTTkSignal

class TTkListWidget:
    def __init__(self, parent=None, **kwargs): ...
    def addItems(self, items): ...
    def currentItem(self): ...
    itemClicked: pyTTkSignal

Input Widgets

Display Widgets

Widgets for displaying information including labels, images, progress bars, scroll bars, and other visual components.

class TTkLabel:
    def __init__(self, parent=None, text="", **kwargs): ...
    def setText(self, text): ...
    def text(self): ...

class TTkImage:
    def __init__(self, parent=None, **kwargs): ...
    def setImage(self, image): ...

class TTkGraph:
    def __init__(self, parent=None, **kwargs): ...
    def addData(self, data): ...

class TTkFancyProgressBar:
    def __init__(self, parent=None, **kwargs): ...
    def setValue(self, value): ...
    def value(self): ...
    valueChanged: pyTTkSignal

class TTkScrollBar:
    def __init__(self, parent=None, **kwargs): ...
    def setValue(self, value): ...
    def value(self): ...
    valueChanged: pyTTkSignal

Display Widgets

Container Widgets

Specialized container widgets including windows, frames, splitters, scrollable areas, tab widgets, and application templates for organizing and structuring complex UIs.

class TTkWindow:
    def __init__(self, parent=None, title="", **kwargs): ...
    def setTitle(self, title): ...
    def title(self): ...

class TTkFrame:
    def __init__(self, parent=None, **kwargs): ...

class TTkSplitter:
    def __init__(self, parent=None, orientation=TTkConstant.Vertical, **kwargs): ...
    def addWidget(self, widget): ...

class TTkScrollArea:
    def __init__(self, parent=None, **kwargs): ...
    def setWidget(self, widget): ...

Container Widgets

Text Editing

Multi-line text editing capabilities with syntax highlighting, line numbers, and advanced text manipulation features.

class TTkTextEdit:
    def __init__(self, parent=None, **kwargs): ...
    def setText(self, text): ...
    def text(self): ...
    def append(self, text): ...
    def clear(self): ...
    textChanged: pyTTkSignal

Text Editing

Model-View Widgets

Data-driven widgets using the Model-View pattern including tables and trees with support for various data sources and custom models.

class TTkTable:
    def __init__(self, parent=None, **kwargs): ...
    def setModel(self, model): ...

class TTkTree:
    def __init__(self, parent=None, **kwargs): ...
    def setModel(self, model): ...

class TTkAbstractTableModel:
    def __init__(self): ...
    def rowCount(self): ...
    def columnCount(self): ...
    def data(self, index): ...

Model-View Widgets

Color and Drawing

Advanced color support, drawing capabilities, and theming system with ANSI color support, gradients, and custom drawing operations.

class TTkColor:
    def __init__(self, fg=None, bg=None, **kwargs): ...
    def foreground(self): ...
    def background(self): ...

class TTkCanvas:
    def __init__(self, **kwargs): ...
    def drawText(self, pos, text, color=None): ...
    def drawChar(self, pos, char, color=None): ...

class TTkString:
    def __init__(self, text="", color=None): ...
    def __str__(self): ...

Color and Drawing

Event System

Signal-slot communication system for event handling and inter-widget communication patterns.

class pyTTkSignal:
    def __init__(self): ...
    def connect(self, slot): ...
    def disconnect(self, slot=None): ...
    def emit(self, *args): ...

def pyTTkSlot():
    """Decorator for slot functions"""
    ...

Event System

File and Dialog Operations

File operations, dialog widgets, and cross-platform utilities for common application tasks.

class TTkFileDialogPicker:
    def __init__(self, parent=None, **kwargs): ...
    def getOpenFileName(self): ...
    def getSaveFileName(self): ...

class TTkMessageBox:
    def __init__(self, parent=None, **kwargs): ...
    def information(self, title, message): ...
    def warning(self, title, message): ...
    def critical(self, title, message): ...

File and Dialog Operations

Utilities and System Classes

Utility classes, system services, and helper functionality including timers, clipboard access, menu systems, and application helpers.

class TTkHelper:
    @staticmethod
    def quit(): ...
    @staticmethod
    def aboutTermTk(): ...
    @staticmethod
    def getTerminalSize(): ...
    quitEvent: pyTTkSignal

class TTkTimer:
    def __init__(self): ...
    def start(self, sec=0.0): ...
    def stop(self): ...
    timeout: pyTTkSignal

class TTkClipboard:
    @staticmethod
    def setText(text): ...
    @staticmethod
    def text(): ...

class TTkSpacer:
    def __init__(self, parent=None, **kwargs): ...

class TTkMenuBarLayout:
    def __init__(self, **kwargs): ...
    def addMenu(self, text, **kwargs): ...

class TTkMenu:
    def __init__(self, parent=None, **kwargs): ...
    def addAction(self, text, callback=None, **kwargs): ...
    def exec(self, pos=None): ...

Utilities and System Classes

Types

Common type definitions used throughout the pyTermTk API:

# Type aliases for common coordinate and size representations
TTkPoint = Tuple[int, int]
TTkSize = Tuple[int, int]

# Constant definitions for common values
class TTkConstant:
    # Focus policies
    NoFocus = 0
    TabFocus = 1
    ClickFocus = 2
    StrongFocus = 3
    
    # Alignment constants
    LEFT_ALIGN = 0x0001
    RIGHT_ALIGN = 0x0002
    CENTER_ALIGN = 0x0004
    
    # Orientation
    Horizontal = 0
    Vertical = 1
    
    # Mouse buttons
    LeftButton = 1
    RightButton = 2
    MiddleButton = 4

# Alias for convenience
TTkK = TTkConstant