Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alejandroautalan/pygubu

A simple GUI builder for the python tkinter module
https://github.com/alejandroautalan/pygubu

gui python tkinter

Last synced: 2 days ago
JSON representation

A simple GUI builder for the python tkinter module

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/alejandroautalan/pygubu.svg?branch=master)](https://travis-ci.org/alejandroautalan/pygubu)

[Leer en Español](LEEME.md)

Welcome to Pygubu!
==================

`Pygubu` is a [RAD tool](https://en.wikipedia.org/wiki/Rapid_application_development) to enable _quick_ and _easy development of user interfaces_ for the Python's `tkinter` module.

The user interfaces designed are saved as [XML](https://en.wikipedia.org/wiki/XML) files, and, by using the _pygubu builder_, these can be loaded by applications dynamically as needed.

Pygubu is inspired by [Glade](https://gitlab.gnome.org/GNOME/glade).

Installation
============

The latest version of pygubu requires Python >= 3.8

You can install pygubu using pip:

```
pip install pygubu
```

Usage
=====

Since version 0.10 the project was splitted in two main modules:

- The **pygubu core** (this project), that load and build user interfaces defined in xml.
- The **interface editor** [pygubu-designer](https://github.com/alejandroautalan/pygubu-designer), that helps you create the xml definition graphically.

Start creating your tkinter application xml UI definition using the pygubu-designer editor.

The following is a UI definition example called [helloworld.ui](https://github.com/alejandroautalan/pygubu-designer/blob/master/examples/helloworld/helloworld.ui):

```xml


200
both
Hello World App
200


200
20
200

true
top



center
Helvetica 26
#0000b8
Hello World !

top





```

Then, you should create your _application script_ as shown below ([helloworld.py](https://github.com/alejandroautalan/pygubu-designer/blob/master/examples/helloworld/helloworld.py)):

```python
# helloworld.py
import pathlib
import tkinter as tk
import tkinter.ttk as ttk
import pygubu

PROJECT_PATH = pathlib.Path(__file__).parent
PROJECT_UI = PROJECT_PATH / "helloworld.ui"

class HelloworldApp:
def __init__(self, master=None):
# 1: Create a builder and setup resources path (if you have images)
self.builder = builder = pygubu.Builder()
builder.add_resource_path(PROJECT_PATH)

# 2: Load a ui file
builder.add_from_file(PROJECT_UI)

# 3: Create the mainwindow
self.mainwindow = builder.get_object('mainwindow', master)

# 4: Connect callbacks
builder.connect_callbacks(self)

def run(self):
self.mainwindow.mainloop()

if __name__ == '__main__':
app = HelloworldApp()
app.run()

```

Note: instead of `helloworld.ui`, you should insert the _filename_ (or full path) of your UI definition:

```python
PROJECT_UI = PROJECT_PATH / "helloworld.ui"
```

Note: instead of 'mainwindow', you should have the name of your _main_widget_ (the parent of all widgets) in the following line:

```python
self.mainwindow = builder.get_object('_your_main_widget_')
```

Documentation
=============

Visit the [pygubu wiki](https://github.com/alejandroautalan/pygubu/wiki) for more documentation.

The following are some good tkinter (and tk) references:

- [TkDocs](http://www.tkdocs.com)
- [Graphical User Interfaces with Tk](https://docs.python.org/3/library/tk.html)
- [Tkinter 8.5 reference: a GUI for Python](https://tkdocs.com/shipman)
- [An Introduction to Tkinter](http://effbot.org/tkinterbook) [(archive)](http://web.archive.org/web/20200504141939/http://www.effbot.org/tkinterbook)
- [Tcl/Tk 8.5 Manual](http://www.tcl.tk/man/tcl8.5/)

You can also see the [examples](https://github.com/alejandroautalan/pygubu-designer/tree/master/examples) directory or watch [this introductory video tutorial](http://youtu.be/wuzV9P8geDg).

History
=======

See the list of changes [here](HISTORY.md).