Skip to content

All possible interfaces

Apart from the default Mininterface, the base interface the others are fully compatible with, several interfaces exist at mininterface.interfaces.

shortcut full name
min Mininterface
gui GuiInterface | TkInterface
tui | textual TuiInterface
text | tui TextInterface
web WebInterface

Ordering

We try to obtain the best interface available. By preference, it is gui , then > tui (textual or at least > text), then the original non-interactive > Mininterface is used. The ensures the program to still work in cron jobs etc.

Getting one

Normally, you get an interface through mininterface.run but if you do not wish to parse CLI and config file, you can invoke one directly through from mininterface.interfaces import *. You may as well use the get_interface function to ensure the interface is available or invoke the program with MININTERFACE_INTERFACE environment variable.

Info

Performance boost: Only interfaces that are being used are loaded into memory for faster start.

Direct invocation

How to invoke a specific interface directly?

from mininterface.interfaces import TuiInterface

with TuiInterface("My program") as m:
    number = m.ask("Returns number", int)

get_interface

Returns the best available interface.

Similar to mininterface.run but without CLI or config file parsing.

from mininterface.interfaces import get_interface
m = get_interface()
m.ask("...")

Parameters:

Name Type Description Default
interface InterfaceType

An interface type of preference.

None
title str

Window title

''
settings Optional[MininterfaceSettings] None
env Optional[EnvClass]

You can specify the .env attribute of the returned object.

None

Environment variable MININTERFACE_INTERFACE

From outside, you may override the default interface choice by the environment variable.

$ MININTERFACE_INTERFACE=web program.py

Mininterface

The base interface.

GuiInterface or TkInterface or 'gui'

A tkinter window. It inherits from GuiSettings.

$ MININTERFACE_INTERFACE=gui ./program.py

Hello world example: GUI window
The code for generating screenshots is taken from the Introduction.

TuiInterface or 'tui'

An interactive terminal. Will try to get TextualInterface and TextInterface as a fallback.

TextualInterface

If textual installed, rich and mouse clickable interface is used.

$ MININTERFACE_INTERFACE=tui ./program.py

Hello world example: TUI fallback

TextInterface

Plain text only interface with no dependency as a fallback. The non-interactive session becomes interactive if possible but there is no mouse support. Does not clear whole screen as TextualInterface if it suits better your program flow.

$ MININTERFACE_INTERFACE=text ./program.py
Hello world example: text fallback

WebInterface or 'web'

Exposed to a web.

You can expose any script to the web by invoking it through the bundled mininterface program.

$ mininterface web ./program.py --port 9997

But still, you have the possibility to invoke the web by preference in the run or get_interface method, direct invocation through importing WebInterface from mininterface.interfaces, or through the environment variable.

$ MININTERFACE_INTERFACE=web ./program.py
Serving './program.py' on http://localhost:64646

Press Ctrl+C to quit
Hello world example: web

Caveat

Should you plan to use the WebInterface, we recommend invoking it be the first thing your program do. All the statements before invoking it run multiple times!

hello = "world"  # This line would run thrice!
with run(interface="web") as m:
    m.form({"one": 1})
    m.form({"two": 2})

Warning

Still in beta. We appreciate help with testing etc.

ReplInterface

A debug terminal. Invokes a breakpoint after every dialog.