Python Terminal Toolkit for creating sophisticated text-based user interfaces with Qt-like API and full widget support
npx @tessl/cli install tessl/pypi-pytermtk@0.46.0A 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.
pip install pyTermTkimport TermTkStandard 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, TTkListWidgetFor advanced widgets from specialized modules:
from TermTk.TTkWidgets.Fancy import TTkFancyProgressBar#!/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()pyTermTk follows a layered architecture inspired by Qt's design patterns:
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.
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): ...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): ...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: pyTTkSignalWidgets 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: pyTTkSignalSpecialized 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): ...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: pyTTkSignalData-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): ...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): ...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"""
...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): ...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): ...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