A declarative GUI framework for Python built on wxPython that makes creating desktop applications simple and maintainable.
- Declarative Syntax: Define your GUI layout using Python class attributes
- Automatic Layout: Framework handles widget positioning and sizing automatically
- Flexible Event Binding: Bind callbacks using decorators or direct assignment
- Nested Forms: Compose complex UIs from reusable form components
- Cross-Platform: Works on Windows, macOS, and Linux via wxPython
pip install gui_builderRequires Python 3.8.6 or higher.
importwxfromgui_builderimportfields, formsclassSimpleForm(forms.Frame):
# Define UI elements as class attributesname=fields.Text(label="Your Name")
greeting=fields.Button(label="Say Hello")
output=fields.Text(multiline=True, readonly=True)
# Bind event handler with decorator@greeting.add_callbackdefon_greeting(self):
self.output.set_value(f"Hello, {self.name.get_value()}!")
if__name__=="__main__":
app=wx.App()
frame=SimpleForm(title="GUI Builder Demo", top_level_window=True)
frame.display()
app.MainLoop()Fields are declared as class attributes and represent UI controls:
classMyForm(forms.Frame):
text_input=fields.Text(label="Name")
number=fields.IntText(label="Age", default_value=0)
accept=fields.CheckBox(label="I agree")
submit=fields.Button(label="Submit")Available field types include: Text, IntText, CheckBox, Button, ComboBox, ListBox, RadioButtonGroup, DatePicker, FilePicker, Slider, SpinBox, ProgressBar, TreeView, Link, StaticText, Image, and more.
Bind callbacks using the @field.add_callback decorator:
classMyForm(forms.Frame):
button=fields.Button(label="Click Me")
@button.add_callbackdefon_click(self):
print("Button clicked!")Or use the callback parameter directly:
classMyForm(forms.Frame):
defhandle_click(self):
print("Button clicked!")
button=fields.Button(label="Click Me", callback=handle_click)Create reusable form components by nesting forms:
classOptionsPanel(forms.Panel):
option_a=fields.CheckBox(label="Enable Feature A")
option_b=fields.CheckBox(label="Enable Feature B")
classMainFrame(forms.Frame):
name=fields.Text(label="Name")
options=OptionsPanel()
submit=fields.Button(label="Submit")- Frame: Top-level window
- Dialog: Modal or non-modal dialog window
- Panel: Container for grouping controls
- SizedPanel: Panel with automatic sizing
- SizedFrame: Frame with automatic sizing
- SizedDialog: Dialog with automatic sizing
- Notebook: Tabbed container
# Set a field valueself.name.set_value("John")
# Get a field valuename=self.name.get_value()
# Set multiple values using a dictionaryself.set_values({"name": "John", "age": 30})The examples/ directory contains working demonstrations:
- link.py: Basic link field usage
- nested.py: Nested forms and panels
- radio_buttons.py: Radio button groups
- text_conversion.py: Text encoding/decoding with multiple controls
Run any example with:
python examples/nested.pyUse FreezeAndThaw to optimize UI updates and prevent flickering:
fromgui_builder.context_managersimportFreezeAndThawwithFreezeAndThaw(self.text_field):
# Multiple updates happen without visual flickeringself.text_field.set_value(large_text)
self.text_field.set_insertion_point(0)Install development dependencies:
uv syncThe project uses:
hatchlingfor build backenduvfor dependency managementpyproject.tomlfor configuration
MIT License - see LICENSE.txt for details.