Eric - "No module named MainWindow"
Phil
phil_lor at bigpond.com
Sun Feb 17 18:04:23 EST 2013
On 17/02/13 21:35, Vincent Vande Vyvre wrote:
> Le 17/02/13 10:08, Phil a écrit :
>> Thank you for reading this.
>>
>> I've been playing with Eric all day and I almost have a working GUI
>> application, but not quite. I have followed the two tutorials on the
>> Eric site and I'm sure that I haven't miss entered anything and so I
<cut>
> Are you sure you have a class MainWindow in your ui.MainWindow.py ?
>
> Can you show us the code of this MainWindow ?
Thank you Vincent and Joel. I think I have already tried every
conceivable combination but I still cannot get past the error message.
At the risk of burdening the list with lots of code I have decided to
show the code as it stands. It's substantially that from the mini
browser example.
This is the auto generated code for Ui_mainWindow.py:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file
'/home/phil/mainWindow.ui'
#
# Created: Sun Feb 17 15:54:33 2013
# by: PyQt4 UI code generator 4.9.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(200, 200)
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.pushButton = QtGui.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(40, 120, 91, 24))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
MainWindow.setCentralWidget(self.centralWidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
"MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("MainWindow",
"PushButton", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
This is the code for mainWindow.py"
class MainWindow(QMainWindow, Ui_MainWindow):
"""
Class documentation goes here.
"""
def __init__(self, parent = None):
"""
Constructor
"""
QMainWindow.__init__(self, parent)
self.setupUi(self)
And this is the main script that I had originally used and named new_gui.py:
from PyQt4 import QtCore, QtGui
from ui.MainWindow import MainWindow
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
ui = MainWindow()
ui.show()
sys.exit(app.exec_())
Finally, for completeness, this is the error message when I attempt to
execute new_gui.py:
The debugged program raised the exception unhandled ImportError
"No module named mainWindow"
File: /home/phil/new_gui.py, Line: 2
Could it simply be a case of conflict between my file names and the
module name?
--
Regards,
Phil
More information about the Python-list
mailing list