Skip to main content

wizard-tk-bridge

wizard-ui-bridge is the user-interface-independent way for a wizard to ask a user questions.

wizard-tk-bridge is the Tk (Tkinter) implementation of this user-interface-independent way for a wizard to ask a user questions. A wizard written for wizard-ui-bridge works out of the box if passed a wizard-tk-bridge as bridge.

Is this package for you?

This package is a good fit when one or more of these apply:

  • You have a wizard written for wizard-ui-bridge and want to run it in a graphical user interface, without changing a line of the wizard.
  • Your application is a Tkinter application, and its questions belong in real widgets rather than in a terminal.
  • You want what a console cannot offer: a native file and directory picker, a month calendar for dates, help texts as hover tooltips, an editable table with add-row and remove-row buttons, and a whole form on one screen that the user fills in any order.
  • Your program is otherwise a plain command-line tool, and you want to ask through a window without writing any Tkinter code of your own.
  • You want to decide where the wizard appears: in a window of its own over your application, or inside a panel your application built.

This package is probably not the right one when:

  • Your program runs in a terminal, or on a machine with no display. Use the console or Textual bridge of wizard-ui-bridge.
  • Your application uses another graphical toolkit, such as Qt, wxPython or GTK. Write a bridge for that toolkit instead, by subclassing WizardUiBridge.
  • You want a general widget toolkit. Use Tkinter directly.

Installation

wizard-tk-bridge requires Python 3.12 or newer, and the standard library module tkinter.

pip install --upgrade wizard-tk-bridge

This installs wizard-ui-bridge as well, since a Tk bridge is a WizardUiBridge.

tkinter belongs to the standard library, but it is not a pure Python module, and several Linux distributions leave it out of their base Python package. A standard library module is not something pip can install, so add it with the system package manager instead:

sudo apt install python3-tk       # Debian, Ubuntu
sudo dnf install python3-tkinter  # Fedora, RHEL

The usual CPython installers for Windows and macOS already include it.

Quick start

Ask a few questions from a program that has no window of its own:

from wizard_tk_bridge import WizardUiBridgeTk

bridge = WizardUiBridgeTk()
try:
    name = bridge.ask_text('Your name?', nullable=True)
    topping = bridge.ask_choice('Favorite topping?',
                                choices=('Mushroom', 'Pepperoni', 'Olive'))
    cheese = bridge.ask_yes_no('Extra cheese?', default=False)
finally:
    bridge.close()
print(f'{name or "Anonymous"} orders {topping}, extra cheese: {cheese}')

Every ask method blocks until the user answers, so the wizard stays straight-line code. No mainloop() call is needed: the ask methods pump the Tk event loop themselves and return as soon as the answer is in, and the program is not left running an event loop once the wizard closes. All questions of one session are asked in the same reused window, so the session does not jump around the display.

Every question also carries Back, Out one level and Abort buttons, which raise WizardBack, WizardCancelLevel and WizardAbort instead of returning an answer. Closing the wizard's own window, or pressing Cmd-W (Ctrl-W on Windows) in it, is an abort as well. The short example above catches none of them and simply lets them propagate.

Where the wizard appears

That is the one question the Tk bridge adds to the wizard-ui-bridge API, and the constructor answers it:

Your application Arguments What the bridge builds
A command-line program with no Tkinter code neither a hidden root, and the wizard's own window over it
Has windows of its own parent=widget a new window over the widget's window
Has a container set aside for the wizard area=container the wizard's widgets inside that container

parent and area are mutually exclusive; giving both raises ValueError. The visible part is built on the first question, so a bridge that is never asked anything puts nothing on the screen.

modal (default True) decides whether the wizard grabs its window — or the window containing area — for the whole session, leaving the rest of that window unusable meanwhile. Only the application knows whether its other content should stay usable, which is why it decides. An embedded wizard normally passes modal=False, since keeping the rest of the window usable is the reason to embed rather than pop up.

close() is not optional. It releases the modal grab, destroys the wizard's own window or clears its area, and destroys the hidden root when the bridge owns one. Call it from a finally, because a wizard's normal way of ending is often a WizardNavigation exception rather than a return. Calling it twice is harmless.

What the user gets

WizardUiBridgeTk overrides every ask method, the inheritable ones included — above all ask_path() and ask_form(), where a graphical interface beats the base class fallback outright:

Ask method What the user gets
ask_text a text entry, masked when sensitive
ask_int a numeric entry, re-asked until the value parses and fits its bounds
ask_path an entry with a Browse button opening the native file or directory picker
ask_yes_no a Yes and a No button
ask_choice / ask_multi a single- / multi-selection list
ask_table an editable grid, with Add row and Remove row when the question allows a variable number of rows
ask_form every field of the form on one screen, answered in any order

In a form, a field's help_text becomes a hover tooltip rather than an extra printed line, the float, time and duration fields show their accepted format as greyed placeholder text, and a date or date-time field adds a Pick button opening a month calendar.

show() appends to a message area kept above the current question, so earlier messages stay readable as the wizard moves on. They disappear with the window, so a final message needs a question after it to be seen at all — exactly as on the Textual bridge.

A graphical interface has no console to write side notes to, so error_file() returns a stream that discards what is written to it. Pass WizardUiBridgeTk(log=stream) to send those diagnostics somewhere real, such as an open log file.

Relation to wizard-ui-bridge

wizard-tk-bridge and wizard-ui-bridge are built from the same repository and released together, so a version of this package requires the matching version of wizard-ui-bridge, or newer.

Documentation

License

MIT

Test summary

  • Test result: 1124 passed, 9 deselected in 42s
  • No flake8 warnings.
  • No mypy errors found.
  • No pylint warnings.
  • No python layout warnings.
  • Built version(s): 1.5
  • Build and test using Python 3.15.1

Metadata

Release files for wizard-tk-bridge 1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wizard-tk-bridge 1.5
File Size Uploaded Provenance Actions
wizard_tk_bridge-1.5.tar.gz 38.4 kB Without provenance Details for wizard_tk_bridge-1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wizard-tk-bridge 1.5
File Interpreter ABI Platform Actions
wizard_tk_bridge-1.5-py3-none-any.whl Python 3 none any Details for wizard_tk_bridge-1.5-py3-none-any.whl

Total release size: 80.2 kB

Release files / wizard_tk_bridge-1.5.tar.gz

Download URL wizard_tk_bridge-1.5.tar.gz
Size 38.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6293071f7dad7e04808490434ccd6cf29bfe4acb95f7444b982792e6df5de58b
BLAKE2b-256 checksum
How to use checksums
6637b782da24a18d9424ff9ece8b5804a104bc04f9c1ff918f05837616868aa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Release files / wizard_tk_bridge-1.5-py3-none-any.whl

Download URL wizard_tk_bridge-1.5-py3-none-any.whl
Size 41.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04472d2fd34753988258ef9e1dd75bee79fa3e6d73eecefd58fd89b9e1943d9c
BLAKE2b-256 checksum
How to use checksums
718874cff0ca9c9c6beba93a6b128d084756c5d06258dd507ad06f9735e24288
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Security for wizard-tk-bridge 1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.5 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page