Skip to main content

Dynamic and customizable Tkinter input dialogs with text fields, alternatives, and typed results

Project description

PePy statistics
PyPI Downloads

dynamicinputbox

A dynamic and customizable input dialog box built with Tkinter.

dynamicinputbox creates a dialog window that can:

  • show an optional message
  • collect one or more text inputs
  • support default values and preset placeholder text
  • hide sensitive input behind a masking character
  • present alternative selections through comboboxes
  • return the clicked button together with collected values

Installation

pip install dynamicinputbox

Basic usage

from dynamicinputbox import DynamicInputBox

dlg = DynamicInputBox(
    title = 'Example',
    message = 'Enter your information',
    inputs = [
        { 'label': 'Username', 'name': 'username' },
        { 'label': 'Password', 'name': 'password', 'show': '*' },
    ],
    buttons = [ 'OK', 'Cancel' ],
    cancel_button = 'Cancel',
).show()

result = dlg.get( dictionary = True )
print( result )

See demo.py for further examples

Parameters

General

  • title (str): Window title. Default is "DynamicInputBox".
  • message (str | None): Optional message displayed above the dialog content.

Inputs

  • inputs (list[InputDict] | None): Collection of input definitions.

Each input definition supports:

  • label (str): Display label for the input field.
  • name (str, optional): Name used as the key in the returned input data. If omitted, a name is generated automatically.
  • default (str, optional): Initial text shown in the input field.
  • show (str, optional): Masking character for hidden input, such as passwords.
  • preset (str, optional): Placeholder-style text shown until the user starts typing.

Alternatives

  • alternatives (list[AlternativeDict] | None): Collection of alternative selection definitions.

Each alternative definition supports:

  • label (str): Display label for the alternative field.
  • options (list[str] | None): Selectable values shown in the combobox.
  • default (str | None): Initially selected value.

Buttons

  • buttons (list[str]): Labels for buttons shown in the dialog. Default is [ 'OK' ].
  • default_button (str | None): Button triggered by Enter.
  • cancel_button (str | None): Button triggered by Escape and intended to represent cancellation.

Behavior

  • dictionary (bool): Default result format used by get(). If True, get() returns dictionary form unless overridden.
  • wipe_after_get (bool): If True, secure values are wiped after they are retrieved.
  • topmost (bool): Whether the dialog should stay above other windows.
  • resizable (bool): Whether the dialog window should be resizable.
  • parent (Tk | Toplevel | None): Optional parent window.

Layout

  • message_wraplength (int | None): Preferred wrap width for the message area, in pixels.
  • max_width_ratio (float): Maximum portion of screen width the dialog may occupy.
  • min_width_px (int): Minimum dialog width in pixels.
  • max_width_px (int | None): Optional absolute maximum dialog width in pixels.
  • padding_px (int): Base padding value for layout.

Return values

The dialog instance is returned from .show().

After the dialog closes, call .get() to retrieve the result.

Tuple form

dlg.get()

Returns:

(inputs_dict_or_none, alternatives_dict, clicked_button)

Where:

  • inputs_dict_or_none is dict[str, str | bytearray] | None
  • alternatives_dict is dict[str, str]
  • clicked_button is str

Sensitive inputs defined with show are returned as bytearray.

Dictionary form

dlg.get( dictionary = True )

Returns:

{
    'button': 'OK',
    'inputs': { ... },
    'alternatives': { ... },
}

Notes:

  • 'button' is always included
  • 'inputs' is only included if input fields were defined
  • 'alternatives' is only included if alternative fields were defined

Secure input handling

Inputs configured with show are internally wrapped in SecureString and returned as bytearray values rather than plain strings. This allows the internal buffer to be wiped after retrieval when wipe_after_get = True.

Public types

The package exposes a few public helper types:

  • InputDict
  • AlternativeDict
  • Result
  • ResultDict
  • ResultTuple
  • SecureString

Example:

from dynamicinputbox import DynamicInputBox, InputDict, ResultDict

Legacy API

The legacy single-input API is still supported for backward compatibility.

Deprecated parameters:

  • input
  • input_default
  • input_label
  • input_show

Example:

dlg = DynamicInputBox(
    title = 'Legacy example',
    message = 'Enter a value',
    input = True,
    input_label = 'Value',
    input_default = 'Example',
    input_show = '*',
).show()

print( dlg.get( dictionary = True ) )

New code should prefer inputs = [...].

Imports and backward compatibility

The preferred import style is:

from dynamicinputbox import DynamicInputBox

For backward compatibility, the legacy alias is also still available:

from dynamicinputbox import dynamic_inputbox

Older module-path imports can still work through a compatibility shim:

from dynamicinputbox.dynamicinputbox import DynamicInputBox
from dynamicinputbox.dynamicinputbox import dynamic_inputbox

New code should prefer importing directly from dynamicinputbox.

Notes

  • Built on Tkinter
  • Designed for simple desktop dialogs
  • Uses comboboxes for alternative selections
  • Intended to work across Windows, macOS, and Linux environments where Tkinter is available

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamicinputbox-3.0.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamicinputbox-3.0-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file dynamicinputbox-3.0.tar.gz.

File metadata

  • Download URL: dynamicinputbox-3.0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dynamicinputbox-3.0.tar.gz
Algorithm Hash digest
SHA256 90d98e9b4f3b5240263ab2a189d82a35456db7bc7c53a4f7fb663899dc24783f
MD5 61af7191ced9a63815f0844e126f1f36
BLAKE2b-256 1fd34c98ae77a554373146bf1123c4c1dc73860ed21e350b633c3a60d6d7cc5b

See more details on using hashes here.

File details

Details for the file dynamicinputbox-3.0-py3-none-any.whl.

File metadata

  • Download URL: dynamicinputbox-3.0-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dynamicinputbox-3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 023313934bef697de37fc56879d9d0ce3ace3fdf65ae5205b51ac766dadbea1e
MD5 46553e29e3b82098aeba63823e2fe91f
BLAKE2b-256 29acae5b627d33167885be7377f3b2faa82aac6acfdd09c480a878ccbb144824

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page