How to use Pygubu – Python

Question:

I am trying to use pygubu from the first time to make better GUI’s. I have installed it using pip and it has installed correctly. However when I try and run the example code Here (At the bottom of the web page) I get the error

AttributeError: module ‘pygubu’ has no attribute ‘Builder’

I don’t know if this code is correct or not. I have looked for ways to use this tool but all I can find are links and videos for installing it. I have also tried This video but can’t figure out how to open/run/use. I am using python-idle if that is the issue. The code (if you don’t want to follow the link) is:

# 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()

I would appreciate any help. Also when I try installing it again – just to check – I get:

My cmd

Asked By: Thomas

||

Answers:

Pygubu is an application. Find it in files from C: drive. The code:

# 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()

Is run after you have created your UI (The format that this application uses) and that the name of the UI specified is helloworld.ui.

Note that instead of helloworld.ui in the following line:

builder.add_from_file(‘helloworld.ui’) You should insert the filename
(or path) of your just saved UI definition.

Note also that instead of ‘mainwindow’ in the following line:

self.mainwindow = builder.get_object(‘mainwindow’) You should have the
name of your main widget (the parent of all widgets), otherwise you
will get an error similar to the following:

Exception: Widget not defined.

This link explains the usage better than one stated in question

Answered By: Thomas

Bien, a mí me sucedió lo mismo, pero yo lo arregle, actualizando una librería a la última versión en la que estoy escribiendo este texto.
La librería que actualize fue:

AwesomeTkinter
(A la última versión)
2021.11.8 quedando hasi:

AwesomeTkinter 2021.11.8

Y pues ya con esto quedó bien.

Answered By: Cris M Vel C
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.