Reputation: 5935
I installed Qt5.3(32 bit) installer on my linux 32 bit computer.
Then i installed last version of sip - sip4.16.4
Then i installed last version of pyqt - PyQt-x11-gpl-4.11.3.tar.gz from http://www.riverbankcomputing.co.uk/software/pyqt/download
In my computer python2.7 and python3.2 versions are installed. When i try to install with python2.7, i took some errors. Then i tried to install it with pthon3.2. No errors happened, and i installed it correctly using python3.2
I installed both py2.7-dev and py3.2-dev package.
gdb,gcc,g++,python2.7,python3.2,build-essential all is installed in my computer.
I installed Qt Designer from the Software Center.
Then i put a simple button following the instructions of the tutorial : http://www.youtube.com/watch?v=GLqrzLIIW2E
Then, i save the example.ui
Then, I give the following command in terminal: pyuic4 example.ui > example.py . It converted the .ui file to .py file. Then i make the necessary modifications told in the youtube tutorial i told above.
- When i run the final version of the python file with python3.2, it gives the error:
Traceback (most recent call last):
File "outFile_ui.py", line 12, in <module>
from PyQt4 import QtCore, QtGui
ImportError: cannot import name QtGui
- Why i am taking this error? I think the problem is at nonmatching version,or installation etc. But i installed again and again. Nothing changed unfortunately. I searched all about the problem on the web. Similar problems exist,however none of them worked for me.
If you want to see the python file which i run on the terminal, it is :
from PyQt4 import QtCore, QtGui
import sys
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 300)
self.horizontalLayout = QtGui.QHBoxLayout(Form)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.printHam_btn = QtGui.QPushButton(Form)
self.printHam_btn.setObjectName(_fromUtf8("printHam_btn"))
self.verticalLayout.addWidget(self.printHam_btn)
self.horizontalLayout.addLayout(self.verticalLayout)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Super Ham", None))
self.printHam_btn.setText(_translate("Form", "Print HAm", None))
self.printHam_btn.clicked.connect(self.printHam)
def printHam(self):
print ("Ham!")
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Ui_Form()
ex.show()
sys.exit(app.exec_())
Upvotes: 0
Views: 6231
Reputation: 5935
After converting .ui to .py code, it is required to add a main function. After main function is added properly, it runs perfectly.
Upvotes: 1