A simple GUI designer for the python tkinter module

Overview

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

Pygubu works with Python 2.7 or Python 3

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>
  <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>
          <property name="column">0</property>
          <property name="propagate">True</property>
          <property name="row">0</property>
          <property name="sticky">nsew</property>
          <rows>
            <row id="0">
              <property name="weight">1</property>
            </row>
          </rows>
          <columns>
            <column id="0">
              <property name="weight">1</property>
            </column>
          </columns>
        </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>
              <property name="column">0</property>
              <property name="propagate">True</property>
              <property name="row">0</property>
            </layout>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

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

# helloworld.py
import tkinter as tk
import pygubu


class HelloWorldApp:
    
    def __init__(self):

        #1: Create a builder
        self.builder = builder = pygubu.Builder()

        #2: Load an ui file
        builder.add_from_file('helloworld.ui')

        #3: Create the mainwindow
        self.mainwindow = builder.get_object('mainwindow')
        
    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:

builder.add_from_file('your_ui_definition.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.

Comments
  • error when loading on macOS

    error when loading on macOS

    $ pygubu-designer
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.6/bin/pygubu-designer", line 11, in <module>
        load_entry_point('pygubu==0.9.8.1', 'gui_scripts', 'pygubu-designer')()
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 565, in load_entry_point
        return get_distribution(dist).load_entry_point(group, name)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
        return ep.load()
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2291, in load
        return self.resolve()
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2297, in resolve
        module = __import__(self.module_name, fromlist=['__name__'], level=0)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pygubudesigner/main.py", line 46, in <module>
        from .uitreeeditor import WidgetsTreeEditor
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pygubudesigner/uitreeeditor.py", line 31, in <module>
        from .widgeteditor import WidgetEditor
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pygubudesigner/widgeteditor.py", line 28, in <module>
        from pygubudesigner.propertieseditor import PropertiesEditor
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pygubudesigner/propertieseditor.py", line 31, in <module>
        from pygubudesigner.i18n import translator as _
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pygubudesigner/i18n.py", line 32, in <module>
        lc, encoding = locale.getdefaultlocale()
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/locale.py", line 562, in getdefaultlocale
        return _parse_localename(localename)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/locale.py", line 490, in _parse_localename
        raise ValueError('unknown locale: %s' % localename)
    ValueError: unknown locale: UTF-8
    
    opened by yuniq-neko 14
  • Center pygubu window on screen

    Center pygubu window on screen

    Is there any way to center a pygubu window in the middle of the os screen? At the moment it opens up at random locations and I could not find anything in my search to center the ui in the middle of the screen. Any help will be appreciated.

    opened by LalFX 8
  • How to get string from an entry box?

    How to get string from an entry box?

    I have a form with an entry box, but I don't know how to read the data from it. It would be something like "instr = namespace.xxx.get()", but what is xxx and what namespace is it in? Thanks.

    Regards, Allen

    opened by awindhorn 8
  • bash: pygubu-designer: command not found

    bash: pygubu-designer: command not found

    Having installed it via pip3.5 on Linux, the command "pygubu-designer" returns an error:

    bash: pygubu-designer: command not found
    

    although "import pygubu" in REPL works well.

    opened by GildedHonour 8
  • Problem compiling stand-alone with nuitka cross compiler

    Problem compiling stand-alone with nuitka cross compiler

    Hello,

    I was trying to compile my python program using Nuitka cross platform compiler.

    The compile worked but it threw the following errors and when I hit the executable it fails to load the window. Version of Nuitka 0.5,15 Python 3.4

    The command execution I use is: nuitka --mingw --standalone --remove-output

    Has pygubu been compiled as a standalone, If so with which products

    Nuitka:WARNING:C:\Python34\Lib\site-packages\pygubu\widgets\pathchooserinput.py:8: Cannot find 'Tkinter' in package 'pygubu.widgets' as absolute import. Nuitka:WARNING:C:\Python34\Lib\site-packages\pygubu\widgets\pathchooserinput.py:9: Cannot find 'ttk' in package 'pygubu.widgets' as absolute import. Nuitka:WARNING:C:\Python34\Lib\site-packages\pygubu\widgets\pathchooserinput.py:10: Cannot find 'tkFileDialog' in package 'pygubu.widgets' as absolute import. Nuitka:WARNING:C:\Python34\Lib\site-packages\pygubu\builder__init__.py:28: Cannot find 'Tkinter' in package 'pygubu.builder' as absolute import. Nuitka:WARNING:C:\Python34\Lib\site-packages\pygubu\stockimage.py:27: Cannot find 'Tkinter' in package 'pygubu' as absolute import.

    opened by tcareyintx 8
  • AttributeError

    AttributeError

    Hello,

    I just downloaded and tried to run pygubu but it does nothing when called pygubu or pygubu.pyw and when I try pygubu.pyc it returns an AttributeError.

    D:\Python27\Scripts>pygubu

    D:\Python27\Scripts>pygubu.pyw

    D:\Python27\Scripts>pygubu.pyc Running Python sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0) on 'win32' Running Python sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0) on 'win32' Traceback (most recent call last): File "D:\Python27\Scripts\pygubu.pyw", line 42, in import pygubu File "D:\Python27\Scripts\pygubu.pyw", line 43, in print("Pygubu: v. %s" % (pygubu.version,)) AttributeError: 'module' object has no attribute 'version'

    D:\Python27\Scripts>

    Any ideias?

    Thanks,

    JM

    opened by jcrmatos 8
  • Preview and actual effect is not consistent

    Preview and actual effect is not consistent

    I want widgets auto expand to max size when main window resizing. in the preview window, it can autoresize, but actual effect it can't.

    here is the ui file as below and python main script:

    <?xml version="1.0" ?>
    <interface>
      <object class="ttk.Panedwindow" id="Panedwindow_1">
        <property name="height">200</property>
        <property name="orient">vertical</property>
        <property name="width">200</property>
        <layout>
          <property name="column">0</property>
          <property name="propagate">True</property>
          <property name="row">0</property>
          <property name="sticky">nesw</property>
          <columns>
            <column id="0">
              <property name="weight">0</property>
            </column>
          </columns>
          <rows>
            <row id="0">
              <property name="weight">0</property>
            </row>
            <row id="1">
              <property name="weight">0</property>
            </row>
          </rows>
        </layout>
        <child>
          <object class="ttk.Panedwindow.Pane" id="Pane_1">
            <property name="weight">1</property>
            <child>
              <object class="pygubu.builder.widgets.scrollbarhelper" id="scrollbarhelper_1">
                <property name="scrolltype">both</property>
                <layout>
                  <property name="column">0</property>
                  <property name="propagate">True</property>
                  <property name="row">0</property>
                </layout>
                <child>
                  <object class="tk.Text" id="Text_1">
                    <property name="height">10</property>
                    <property name="text" translatable="yes">Text_1</property>
                    <property name="width">50</property>
                    <property name="wrap">char</property>
                    <layout>
                      <property name="column">0</property>
                      <property name="propagate">True</property>
                      <property name="row">0</property>
                    </layout>
                  </object>
                </child>
              </object>
            </child>
          </object>
        </child>
        <child>
          <object class="ttk.Panedwindow.Pane" id="Pane_2">
            <property name="weight">1</property>
            <child>
              <object class="pygubu.builder.widgets.scrollbarhelper" id="scrollbarhelper_2">
                <property name="scrolltype">both</property>
                <layout>
                  <property name="column">0</property>
                  <property name="propagate">True</property>
                  <property name="row">0</property>
                </layout>
                <child>
                  <object class="tk.Text" id="Text_2">
                    <property name="height">10</property>
                    <property name="text" translatable="yes">Text_2</property>
                    <property name="width">50</property>
                    <property name="wrap">char</property>
                    <layout>
                      <property name="column">0</property>
                      <property name="propagate">True</property>
                      <property name="row">0</property>
                    </layout>
                  </object>
                </child>
              </object>
            </child>
          </object>
        </child>
      </object>
    </interface>
    
    #test.py
    import tkinter as tk
    import pygubu
    
    class Application:
        def __init__(self, master):
    
            #1: Create a builder
            self.builder = builder = pygubu.Builder()
    
            #2: Load an ui file
            builder.add_from_file('111.ui')
    
            #3: Create the widget using a master as parent
            self.mainwindow = builder.get_object('Panedwindow_1', master)
    
    if __name__ == '__main__':
        root = tk.Tk()
        app = Application(root)
        root.mainloop()
    
    opened by zaazbb 8
  • Run executable file by pyinstaller generated, the erroe showed “ModuleNotFoundError: No module named 'Notebook'”

    Run executable file by pyinstaller generated, the erroe showed “ModuleNotFoundError: No module named 'Notebook'”

    Hi, when I Run executable file by pyinstaller generated, the erroe showed “ModuleNotFoundError: No module named 'Notebook'”. error tip:

    [<class 'ModuleNotFoundError'>] No module named 'Notebook'

    Traceback (most recent call last): File "pygubu\builder.py", line 193, in import_class File "importlib_init.py", line 127, in import_module File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 961, in _find_and_load_unlocked File "", line 219, in _call_with_frames_removed File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 973, in _find_and_load_unlocked ModuleNotFoundError: No module named 'ttk'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "pygubu\builder.py", line 201, in import_class File "importlib_init.py", line 127, in import_module File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 973, in _find_and_load_unlocked ModuleNotFoundError: No module named 'ttk'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "tktools.py", line 235, in File "tktools.py", line 28, in init File "pygubu\builder.py", line 167, in get_object File "pygubu\builder.py", line 215, in _realize File "pygubu\builder.py", line 204, in import_class File "importlib_init.py", line 127, in import_module File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 973, in _find_and_load_unlocked ModuleNotFoundError: No module named 'Notebook'

    File "tktools.py", line 28 code is: self.mainwindow = builder.get_object("notebook1", master)

    this is the minimum example. see the attach files: tk_tools.zip

    pyinstaller --add-data "tools2.ui;." -D tktools2.py

    pygubu 0.25 pygubu-designer 0.30 pyinstaller 5.4.1 pyinstaller-hooks-contrib 2022.10

    note: I debugged and found that it seemed to be PluginManager.py "for _, name, _ in iter_namespace(pygubu.plugins):" not executed, when run exe file.

    so, How should I deal with this problem?

    thanks

    opened by 1893945 7
  • Why not use pkgutil for resource loading?

    Why not use pkgutil for resource loading?

    Pygubu is an ingenious tool that I discovered only now, although I use tkinter for at least 2 years! It's a professionally developed solid piece of code. I tried it and it works as intended out of the box!

    I often put my project in a zip file, rename it to .pyz, and it becomes a single-file cross-platform app (which often only needs python3 installed). To load resources in such an app I use pkgutil.get_data(), which is nice because it works both ways: from a pyz-file and from the original unpacked app while I debug it. And pkgutil is a standard library.

    So, when I use Pygubu I can load .ui files using builder.add_from_string(pkgutil.get_data(PROJECT_MODULE, PROJECT_UI)), but if I use images inside the .ui file, they are not being loaded.

    I understand that Pygubu is adapted for use with PyInstaller and several other packagers, but maybe using pkgutil.get_data() will simplify all this resource-loading? Or maybe I'm doing something wrong?

    Thanks!

    enhancement 
    opened by D0m0 7
  • How to put a picture into a frame?

    How to put a picture into a frame?

    I am trying to display a graph inside of a Tkinter frame. Any hints how to do that? It is a .png file-like object. It will be changed frequently during use. Thanks.

    Regards, Allen

    opened by awindhorn 7
  • How to run pygubu application?

    How to run pygubu application?

    In the README.md file of this repository, there's no specification on how to run the pygubu application/GUI designer. There's just an example of an application created, I suppose, with pygubu, and I was able to run it.

    On my mac OS X, I cannot simply type pygubu on the terminal and the GUI designer appears (like you did in the youtube video). I had to do a painful workaround.

    If I install pygybu using pip3 with the following command:

    pip3 install pygubu
    

    In my Python folder site-packages, I have my pygubu folder (and I can therefore import pygubu from the IDLE), but that folder is simply this: https://github.com/alejandroautalan/pygubu/tree/master/pygubu Which is actually a subfolder of this repository (and not all the repository).

    I couldn't run the pygubu designer from that folder... there was not script to run it, or something similar.

    I decided to clone this whole repository, and I finally discover that under /bin/ there's a script, which allows us to run pygubu.

    This was very painful for me, and I hope you provide a complete guide on how to run the pygubu designer for various platforms, and not just for Ubuntu, where I suppose you can simply type magically pygubu from the terminal.


    Edit:

    I had noticed that I can now run pygubu from the terminal by simply typing pygubu-designer instead of simply pygubu...

    opened by nbro 7
  • class name

    class name

    Hi Alejandroautalan,

    Thank you very much for the fantastic tool! After reviewing a number of tools I decided to use pygubu for my project - I found it the best in terms of ease to use, rich in feature and flexible.

    I use it by generating the code script, sub-classing the generated class and overriding the call back functions - so that the automatically generated code and my hand writing code are completely separated. It worked perfectly until I decided to create a second top-level window - a simple dialog.

    What is bothering me is that I have to re-type the class name every time I need to re-generate and save the code script. Could you please add the class name as an property in the "Appearance" panel, for example, under "id", and use it to generate the code?

    Thanks again for your work - you are making our life much easier!

    enhancement 
    opened by YiQinHuili 1
  • It seems `ScrolledFrame` doesn't work for `place layout`.

    It seems `ScrolledFrame` doesn't work for `place layout`.

    Hello, @alejandroautalan , it seems ScrolledFrame doesn't work for place layout.
    my code:

    import tkinter as tk
    from pygubu.widgets.scrolledframe import ScrolledFrame
    
    root = tk.Tk()
    
    scrolledframe =  ScrolledFrame(
        root,
        scrolltype="horizontal"
    )
    
    prev_x = 0
    for i in range(100):
        label= Label(
            scrolledframe.innerframe,
            text="ABCD ")
        label.place(x=prev_x, y=0)
        prev_x += label.winfo_reqwidth()    
        
    scrolledframe.place(x=0, y=0, height=500, width=200)
    
    root.mainloop()
    

    and the widget appears without scrollbar.
    Screenshot from 2022-07-21 04-19-38

    Regards. larryw3i

    bug 
    opened by larryw3i 3
  • pygubu on conda-forge

    pygubu on conda-forge

    Dear developers,

    Could you please publish pygubu on conda-forge?

    Many people use conda for package installation/management. Providing pygubu only through pypi currently makes it impossible to implement it as a dependency on conda packages (see conda-build issue #548).

    Creating a conda-forge recipe for a PyPI package like pygubu seems easy (see conda-forge site). There is Grayskull, a conda recipe generator (also available online).

    opened by dact221 1
  • pygubu-designer goes to sleep almost forever on Ubuntu 18.04

    pygubu-designer goes to sleep almost forever on Ubuntu 18.04

    Installed pygubu and pygubu-designer on Ubuntu 18.04 LTS on Jetson Nano. Installed as user so executable is in $HOME/.local.bin which is in PATH. Type pygubu-designer, get three lines of version info. Then nothing happens for at least three minutes, sometimes forever. Ran strace and found a semi-infinite list of poll calls returning -1.

    For the record, running the app on a Raspberry Pi 4 opens the root window almost immediately. >_< o_O

    Any theories on what's happening (or not happening) here?

    opened by twrackers 3
  • I'm just a beginner. How to put other ui file into existing frame

    I'm just a beginner. How to put other ui file into existing frame

    I don't know what hit me to make this in python, but I want to make a simple gui for a home raspberry pi information device. Well the ui is something that doesn't make problems for me. However I'm bad in python especially that I've never learned it and just done the project only looking through examples. Now here's a Problem. Im using that typical code with class i called gui and init with creating the builder and importing ui file. Now let's say at the bottom of ui there are 3 buttons to switch one frame (frame_4) in my case to display a small information. So as I said I'm new to Python and I have no idea on how to access the builder from callback function after pressing that button. The function is outside gui class. And from there I want to put UI file into a frame that is already existing in created window at start. Normally I would just ask how to get access to builder, but I also have no idea on how to import UI to existing frame. Sorry for no code, I can post image because I'm on my phone and weird things are happening with github on my PC. I can send the code because ui file doesn't fit in one imageIMG_20201113_105550.jpg And I'll remove some of useless imports later. I hope anyone understands me there. Thank you.

    opened by creeper82 0
  • Change frame class from gui

    Change frame class from gui

    Can we have the possibility to override the frame class? I want to have a child class from the frame class that could go through all children and disable them when needed. And I want to be able to use this class from the designer. However the designer doesn't allow To change the class field.

    opened by bojomojo 4
Owner
Alejandro Autalán
Alejandro Autalán
Tkinter-ATM - Python GUI case made with Tkinter

tkinter-ATM Python GUI case made with Tkinter The task of this case was to creat

null 2 Jan 13, 2022
Weather-API-GUI-Tkinter - A weather tool made using tkinter which works by fetching query city weather using an API

Weather-API-GUI-Tkinter ☁️ ❄️ version- 1️⃣ . 0️⃣ . 0️⃣ This repo contains a weat

SasiVatsal 4 Jul 8, 2022
Project made in Qt Designer + Python, for evaluation in the subject Introduction to Programming in IFPE - Paulista campus.

Project made in Qt Designer + Python, for evaluation in the subject Introduction to Programming in IFPE - Paulista campus.

Paola Rodrigues 2 Apr 13, 2022
A GUI calculator made with tkinter module in python

GUI-Calculator A GUI calculator made with tkinter module in python How to setup the calculator If pygame is not installed, go to terminal and do pip i

Eric Jing 0 Aug 25, 2021
A really minimalistic operating system made using python's GUI module Tkinter.

BoxOS V1.0.0 About A really minimalistic operating system made using python's GUI module Tkinter. What seperates it from the other operating systems m

Fahim 1 Feb 20, 2022
Tkinter calculetor - Tkinter calculetor with python

Tkinter_calculetor required to run py file pip install tkinter

Yasir Arafat 0 Feb 7, 2022
LyricsGenerator - A simple GUI made using Python(Tkinter) for generating song lyrics

Lyrics Generator Reference :- https://www.geeksforgeeks.org/create-a-gui-to-extr

Somya Ranjan Sahu 3 Mar 25, 2022
A simple project used Tkinter module to make a seperate window

Project Title This is a program to run a databse where you can store the general information of poeple. This is a very simple project and i have used

Divyansh Bhardwaj 0 Jun 25, 2022
My Git GUI version made in Python and Tkinter.

Description My Git GUI version made in Python and Tkinter. How to use Basically, create a folder in your computer, open the software, select the path

Matheus Golzio 4 Oct 10, 2021
Signin/Signup GUI form using tkinter in python

SignIn-SignUpFormRepo Hello there, I am Shahid and this is the Signin/Signup GUI form using tkinter in python if you want to use avatar images then pa

Shahid Akhtar 1 Nov 9, 2021
Py address book gui - An address book with graphical user interface developed with Python Tkinter

py_address_book_gui An address book with graphical user interface developed with

Milton 4 Feb 1, 2022
GUI based app made in python using tkinter

Virtual Keyboard A GUI application made in python using tkinter This is my first ever proper GUI based application project after learning tkinter rece

AbhineetK 9 Nov 3, 2022
Basic calculator using Tkinter GUI

Basic calculator using Tkinter GUI

Rogerio Penchel 17 Jan 9, 2022
Advanced Zola Cabs integrated with tkinter Graphical User Interface (GUI) made for ZOHO Corp .

ZolaCabs Advanced Zola Cabs integrated with tkinter Graphical User Interface (GUI) made for ZOHO Corp. < Logs > username : zoho password : zoho [ Deve

Mastermind 9 Nov 18, 2021
A GUI for designing Python GUI's for PySimpleGUI.

SimpleGUIBuilder A GUI for designing Python GUI's for PySimpleGUI. Installation There is none :) just download the file from a release and run it. Don

Miguel Martins 63 Nov 17, 2022
PyQt5 Sample GUI Program - Python PyQt5 Sample GUI application

Python PyQt5 Sample GUI application Program work like this Designed GUI using De

Dimuth De Zoysa 5 Mar 27, 2022
The GUI application by Python3.8. Using QT Design draw UI and generator UI XML file provides to PySide2 build GUI components

The GUI application by Python3.8. Using QT Design draw UI and generator UI XML file provides to PySide2 build GUI components. Total adopt OOD design class, service, and abstract class. OOP implemented this project.

Jiage 1 Jan 11, 2022
This simple python program can be used to make FontChooser dialog in Tkinter Applications.

tkFontBox This simple python program can be used to make FontChooser dialog in Tkinter Applications. how to use? Copy the tkFontBox.py file into your

Pawan Kumar Prachi 1 Feb 8, 2022