Giter Site home page Giter Site logo

pygubu's Introduction

Build Status

Leer en Español

Welcome to Pygubu!

Pygubu is a RAD tool to enable quick and easy development of user interfaces for the Python's tkinter module.

The user interfaces designed are saved as XML files, and, by using the pygubu builder, these can be loaded by applications dynamically as needed.

Pygubu is inspired by Glade.

Installation

The latest version of pygubu requires Python >= 3.6

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, 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:

<?xml version='1.0' encoding='utf-8'?>
<interface version="1.2">
  <object class="tk.Toplevel" id="mainwindow">
    <property name="height">200</property>
    <property name="resizable">both</property>
    <property name="title" translatable="yes">Hello World App</property>
    <property name="width">200</property>
    <child>
      <object class="ttk.Frame" id="mainframe">
        <property name="height">200</property>
        <property name="padding">20</property>
        <property name="width">200</property>
        <layout manager="pack">
          <property name="expand">true</property>
          <property name="side">top</property>
        </layout>
        <child>
          <object class="ttk.Label" id="label1">
            <property name="anchor">center</property>
            <property name="font">Helvetica 26</property>
            <property name="foreground">#0000b8</property>
            <property name="text" translatable="yes">Hello World !</property>
            <layout manager="pack">
              <property name="side">top</property>
            </layout>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

Then, you should create your application script as shown below (helloworld.py):

# 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 an 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 that instead of helloworld.ui, you should insert the filename (or full path) of your UI definition:

PROJECT_UI = PROJECT_PATH / "helloworld.ui"

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

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

Documentation

Visit the pygubu wiki for more documentation.

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

You can also see the examples directory or watch this introductory video tutorial.

History

See the list of changes here.

pygubu's People

Contributors

alejandroautalan avatar danicotra avatar zaazbb avatar nbro avatar larryw3i avatar nuno-andre avatar ryaneverett33 avatar tkaluza avatar errmac avatar scls19fr avatar jrezai avatar rdbende avatar orthographic-pedant avatar gulart avatar frainfreeze avatar timgates42 avatar majensen avatar llorc avatar hucste avatar ajasja avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.