Core Module

Main GuiBuilder Class

class qtpyguihelper.GuiBuilder(config_path=None, config_dict=None, backend=None)[source]

Bases: object

Unified GUI builder that automatically selects the appropriate backend.

This class provides a consistent interface that works with Qt, wxPython, tkinter, and GTK backends, automatically selecting the available backend or using the one specified via set_backend().

Parameters:
  • config_path (str | None)

  • config_dict (Dict[str, Any] | None)

  • backend (str | None)

backend

The currently active backend name

Type:

str

builder

The underlying backend-specific builder instance

Example

Basic usage with automatic backend detection:

>>> from qtpyguihelper import GuiBuilder
>>> gui = GuiBuilder('config.json')
>>> gui.show()

Force a specific backend:

>>> gui = GuiBuilder('config.json', backend='gtk')
>>> gui.run()

Use with configuration dictionary:

>>> config = {"window": {"title": "My App"}, "fields": [...]}
>>> gui = GuiBuilder(config_dict=config)
>>> data = gui.get_form_data()
show()[source]

Show the GUI window.

hide()[source]

Hide the GUI window.

get_form_data()[source]

Get all form data as a dictionary.

Return type:

Dict[str, Any]

set_form_data(data)[source]

Set form data from a dictionary.

Parameters:

data (Dict[str, Any])

clear_form()[source]

Clear all form fields.

get_field_value(field_name)[source]

Get the value of a specific field.

Parameters:

field_name (str) – Name of the field to get the value from

Returns:

The current value of the field, or None if field doesn’t exist

Raises:

WidgetError – If the field doesn’t exist or can’t be accessed

Return type:

Any

set_field_value(field_name, value)[source]

Set the value of a specific field.

Parameters:
  • field_name (str) – Name of the field to set

  • value (Any) – Value to set for the field

Returns:

True if the value was set successfully, False otherwise

Raises:

WidgetError – If the field doesn’t exist or value is invalid

Return type:

bool

set_submit_callback(callback)[source]

Set a callback function to be called when the form is submitted.

set_cancel_callback(callback)[source]

Set a callback function to be called when the form is cancelled.

set_custom_button_callback(button_name, callback)[source]

Set a callback function to be called when a custom button is clicked.

Parameters:

button_name (str)

remove_custom_button_callback(button_name)[source]

Remove a custom button callback.

Parameters:

button_name (str)

get_custom_button_names()[source]

Get a list of all custom button names from the configuration.

enable_field(field_name, enabled=True)[source]

Enable or disable a specific field.

Parameters:
show_field(field_name, visible=True)[source]

Show or hide a specific field.

Parameters:
load_data_from_file(data_file_path)[source]

Load form data from a JSON file and populate the GUI.

Parameters:

data_file_path (str)

Return type:

bool

load_data_from_dict(data)[source]

Load form data from a dictionary and populate the GUI.

Parameters:

data (Dict[str, Any])

Return type:

bool

save_data_to_file(data_file_path, include_empty=True)[source]

Save current form data to a JSON file.

Parameters:
  • data_file_path (str)

  • include_empty (bool)

Return type:

bool

run()[source]

Run the GUI application (start the main loop).

close()[source]

Close the GUI application.

static create_and_run(config_path=None, config_dict=None, backend=None)[source]

Create and run a GUI application with automatic backend detection.

Parameters:
  • config_path (str | None) – Path to JSON configuration file

  • config_dict (Dict[str, Any] | None) – Configuration dictionary (alternative to config_path)

  • backend (str | None) – Force a specific backend (‘qt’, ‘wx’, or ‘tk’). If None, auto-detects.

Returns:

GuiBuilder instance

Backend Management

Backend detection and selection for qtpyguihelper. Supports Qt (via qtpy), wxPython, tkinter, and GTK backends.

class qtpyguihelper.backend.BackendManager[source]

Bases: object

Manages GUI backend selection and availability.

SUPPORTED_BACKENDS = ['qt', 'wx', 'tk', 'gtk']
DEFAULT_BACKEND = 'qt'
get_available_backends()[source]

Get list of available backends.

Return type:

List[str]

is_backend_available(backend)[source]

Check if a specific backend is available.

Parameters:

backend (str)

Return type:

bool

get_backend()[source]

Get the current backend, detecting automatically if not set.

Return type:

str

set_backend(backend)[source]

Set the backend to use.

Parameters:

backend (str) – Backend name (‘qt’ or ‘wx’)

Returns:

True if successfully set, False otherwise

Return type:

bool

get_backend_info()[source]

Get information about the current backend.

Return type:

Dict[str, Any]

qtpyguihelper.backend.get_backend()[source]

Get the current GUI backend.

Return type:

str

qtpyguihelper.backend.set_backend(backend)[source]

Set the GUI backend to use.

Parameters:

backend (str)

Return type:

bool

qtpyguihelper.backend.get_available_backends()[source]

Get list of available GUI backends.

Return type:

List[str]

qtpyguihelper.backend.get_backend_info()[source]

Get information about the current backend.

Return type:

Dict[str, Any]

qtpyguihelper.backend.is_backend_available(backend)[source]

Check if a specific backend is available.

Parameters:

backend (str)

Return type:

bool