1

Hello I have a QTDesigner UI file HelloWorld.ui which I am trying to import into a project and execute.

The Project includes HelloWorld.ui file which has been converted into HelloWorld_ui.py using Pyuic5.

The following is the code of app.py

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

import sys
import HelloWorld_ui



class HelloWorld(QDialog, HelloWorld_ui.Ui_HelloWorld):
    def __init__(self):
        QDialog.__init__(self)
        self.setupUi(self)

app = QApplication(sys.argv)
helloworld = HelloWorld()
helloworld.show()
app.exec_()

The following is the error code

Traceback (most recent call last):
  File "/Users/rrpolak/Downloads/Pyt/app.py", line 11, in <module>
    class HelloWorld(QDialog, HelloWorld_ui.Ui_HelloWorld):
AttributeError: module 'HelloWorld_ui' has no attribute 'Ui_HelloWorld'

Process finished with exit code 1

I am trying to understand what is the correct way to call these files in the python program. Any help is appreciated.

The project file is at https://drive.google.com/open?id=18tjLPiCZxTbKaiZShtgu90KyXcFukr6V

I am using PyQt5/Python3.6/Mac.

1 Answer 1

2

If you check the file HelloWorld_ui.py you will notice that there is no class called Ui_HelloWorld, but the class Ui_Dialog:

class Ui_Dialog(object):

so you must use that class:

class HelloWorld(QDialog, HelloWorld_ui.Ui_Dialog):

The name is generated by the name you give to QDialog:

enter image description here

If you want to use HelloWorld you must change it:

enter image description here

convert the .ui to .py again and execute it again obtaining the following:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.