Pyqt calling file created by Qtdesigner

Asked

Viewed 612 times

0

I developed a Pyqt window with Dialog with Buttons Right template but calling me in my main class gives me an attribute error. I saw in the YT video that the guy used Main Window as a template and he just instated Main_main class (Qtgui.Qmainwindow): I already tried to do the same for my template and nothing. Just 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 me the following error:

Attributeerror: 'module' Object has no attribute 'Qdialogwithbuttonsright'

  • Watch out for indentation when collecting code - Yours has a syntax error. Note that you should not keep trying to correct the code after pasting - select all the pasted code and press the formatting button marked as {}

1 answer

3


Well, there are a number of errors in that code, so let’s go in stages;

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

According to, Qdialogwithbuttonsright is a Method that does not exist! And I don’t remember any of the same, until I went to check the documentation to see if it was, but I didn’t find anything, so I don’t know what you meant.

Third, the class Main_principal has to inherit the object QtWidgets.QDialog, that was not imported.

Quarter, the initializer class __init__, has two underlines and in your example there is only one.

Quinto, You didn’t call the superclass super().

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

So to conclude with these code changes that 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 helped, Good luck in school.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.