PyQT calling file created by QtDesigner

0

I developed a dialog in PyQt with Dialog with Buttons Right template, but when calling in my main class it returns an attribute error. I saw in the YT video that the guy used the Main Window as a template and he just installed Main_principal class (QtGui.QMainWindow): I already tried to do the same for my template and nothing. Follow my code

import sys
from PyQt5 import QtCore, QtGui
from sistema import Ui_Dialog
class Main_principal(QtGui.QDialogwithButtonsRight):
   def _init_(self):
   QtGui.QDialogwithButtonsRight.__init__(self)
   self.ui = Ui_Dialog()
   self.ui.setupUi(self)

app = QtGui.QApplication(sys.argv)
programa = Main()
programa.show()
sys.exit(app.exec_())

and returns the following error:

  

AttributeError: 'module' object has no attribute 'QDialogwithButtonsRight'

    
asked by anonymous 08.02.2017 / 16:30

1 answer

3

Well, there are a lot of errors in this code, so let's go through the steps;

First , The error is that in PyQt5 , QApplication is not contained in QtGui , in PyQt4 but then it was moved to QtWidgets ,

QDialogwithButtonsRight is a method that does not exist !, and I do not remember any of them, until I went to check the documentation to see if it was there, but I did not find anything.

so I do not know what you mean.

Third , the Main_principal class must inherit the QtWidgets.QDialog object, which was not imported.

Room , the initializing class __init__ , has two underlines and in its example there is only one.

Fifth , You did not call the superclass super() .

Sixth , in programa = Main() the name of the class that is assigned to the variable, then it would be; programa = Main_principal()

So concluding with these code changes would be a functional result:

import sys
from PyQt5 import QtWidgets
from sistema import Ui_Dialog

class Main_principal(QtWidgets.QDialog):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)



app = QtWidgets.QApplication(sys.argv)
programa = Main_principal()
programa.show()
sys.exit(app.exec_())

I hope I have helped, Good Luck in Studies.

    
09.02.2017 / 02:27