How to use Pygubu - Python

Viewed 8760

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

1 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

Related