Python Forum
[PyQt] error message in pyqt pro
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] error message in pyqt pro
#1
I am having trouble compiling a program which relates to main window and resource file with .ico files.

I suspect it has something to do with the location of the resource file, but this is just a guess.

Any help in this regard would be greatly appreciated

Thank you


.py file:


# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'toolbardemo.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

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_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 40, 381, 16))
self.label.setObjectName(_fromUtf8("label"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.toolBar = QtGui.QToolBar(MainWindow)
self.toolBar.setObjectName(_fromUtf8("toolBar"))
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.actionPlus = QtGui.QAction(MainWindow)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/add.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionPlus.setIcon(icon)
self.actionPlus.setObjectName(_fromUtf8("actionPlus"))
self.actionMinus = QtGui.QAction(MainWindow)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/minus.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionMinus.setIcon(icon1)
self.actionMinus.setObjectName(_fromUtf8("actionMinus"))
self.actionMultiply = QtGui.QAction(MainWindow)
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/multiply.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionMultiply.setIcon(icon2)
self.actionMultiply.setObjectName(_fromUtf8("actionMultiply"))
self.actionDivide = QtGui.QAction(MainWindow)
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/divide.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionDivide.setIcon(icon3)
self.actionDivide.setObjectName(_fromUtf8("actionDivide"))
self.actionEqual = QtGui.QAction(MainWindow)
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/equals.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionEqual.setIcon(icon4)
self.actionEqual.setObjectName(_fromUtf8("actionEqual"))
self.toolBar.addAction(self.actionPlus)
self.toolBar.addAction(self.actionMinus)
self.toolBar.addAction(self.actionMultiply)
self.toolBar.addAction(self.actionDivide)
self.toolBar.addAction(self.actionEqual)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.label.setText(_translate("MainWindow", "TextLabel", None))
self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar", None))
self.actionPlus.setText(_translate("MainWindow", "Plus", None))
self.actionPlus.setToolTip(_translate("MainWindow", "Plus", None))
self.actionMinus.setText(_translate("MainWindow", "Minus", None))
self.actionMinus.setToolTip(_translate("MainWindow", "Minus", None))
self.actionMultiply.setText(_translate("MainWindow", "Multiply", None))
self.actionMultiply.setToolTip(_translate("MainWindow", "Multiply", None))
self.actionDivide.setText(_translate("MainWindow", "Divide", None))
self.actionDivide.setToolTip(_translate("MainWindow", "Divide", None))
self.actionEqual.setText(_translate("MainWindow", "Equal", None))
self.actionEqual.setToolTip(_translate("MainWindow", "Equal", None))

import tmpresource

.pyw file

import sys
from toolbardemo import *

class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.connect(self.ui.actionPlus, QtCore.SIGNAL('tiggered()'), self.plusmessage)
self.connect(self.ui.actionMinus, QtCore.SIGNAL('tiggered()'), self.minusmessage)
self.connect(self.ui.actionMultiply, QtCore.SIGNAL('tiggered()'), self.multiplymessage)
self.connect(self.ui.actionDivide, QtCore.SIGNAL('tiggered()'), self.dividemessage)
self.connect(self.ui.actionEqual, QtCore.SIGNAL('tiggered()'), self.equalmessage)

def plusmessage(self):
self.ui.label.setText("You have selected Plus")

def multiplymessage(self):
self.ui.label.setText("You have selected Multiply")

def minusmessage(self):
self.ui.label.setText("You have selected Minus")

def dividemessage(self):
self.ui.label.setText("You have selected Divide")

def equalmessage(self):
self.ui.label.setText("You have selected Equal")

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())

error message:

Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Traceback (most recent call last):
File "C:\Users\Regan\Documents\inf1511\chapter10\calltoolbar.pyw", line 2, in <module>
from toolbardemo import *
File "C:\Users\Regan\Documents\inf1511\chapter10\toolbardemo.py", line 94, in <module>
import tmpresource_rc
ImportError: No module named 'tmpresource_rc'
>>>
Reply
#2
Please re-post using code tags so it can be read properly. Have a look at other posts if you don't know what I mean.
Reply
#3
I am having trouble compiling a program which relates to main window and resource file with .ico files.

I suspect it has something to do with the location of the resource file, but this is just a guess.

Any help in this regard would be greatly appreciated

Thank you

.py file:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'toolbardemo.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

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_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 40, 381, 16))
self.label.setObjectName(_fromUtf8("label"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.toolBar = QtGui.QToolBar(MainWindow)
self.toolBar.setObjectName(_fromUtf8("toolBar"))
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.actionPlus = QtGui.QAction(MainWindow)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/add.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionPlus.setIcon(icon)
self.actionPlus.setObjectName(_fromUtf8("actionPlus"))
self.actionMinus = QtGui.QAction(MainWindow)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/minus.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionMinus.setIcon(icon1)
self.actionMinus.setObjectName(_fromUtf8("actionMinus"))
self.actionMultiply = QtGui.QAction(MainWindow)
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/multiply.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionMultiply.setIcon(icon2)
self.actionMultiply.setObjectName(_fromUtf8("actionMultiply"))
self.actionDivide = QtGui.QAction(MainWindow)
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/divide.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionDivide.setIcon(icon3)
self.actionDivide.setObjectName(_fromUtf8("actionDivide"))
self.actionEqual = QtGui.QAction(MainWindow)
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/equals.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionEqual.setIcon(icon4)
self.actionEqual.setObjectName(_fromUtf8("actionEqual"))
self.toolBar.addAction(self.actionPlus)
self.toolBar.addAction(self.actionMinus)
self.toolBar.addAction(self.actionMultiply)
self.toolBar.addAction(self.actionDivide)
self.toolBar.addAction(self.actionEqual)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.label.setText(_translate("MainWindow", "TextLabel", None))
self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar", None))
self.actionPlus.setText(_translate("MainWindow", "Plus", None))
self.actionPlus.setToolTip(_translate("MainWindow", "Plus", None))
self.actionMinus.setText(_translate("MainWindow", "Minus", None))
self.actionMinus.setToolTip(_translate("MainWindow", "Minus", None))
self.actionMultiply.setText(_translate("MainWindow", "Multiply", None))
self.actionMultiply.setToolTip(_translate("MainWindow", "Multiply", None))
self.actionDivide.setText(_translate("MainWindow", "Divide", None))
self.actionDivide.setToolTip(_translate("MainWindow", "Divide", None))
self.actionEqual.setText(_translate("MainWindow", "Equal", None))
self.actionEqual.setToolTip(_translate("MainWindow", "Equal", None))

import tmpresource
.pyw file
import sys
from toolbardemo import *

class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.connect(self.ui.actionPlus, QtCore.SIGNAL('tiggered()'), self.plusmessage)
self.connect(self.ui.actionMinus, QtCore.SIGNAL('tiggered()'), self.minusmessage)
self.connect(self.ui.actionMultiply, QtCore.SIGNAL('tiggered()'), self.multiplymessage)
self.connect(self.ui.actionDivide, QtCore.SIGNAL('tiggered()'), self.dividemessage)
self.connect(self.ui.actionEqual, QtCore.SIGNAL('tiggered()'), self.equalmessage)

def plusmessage(self):
self.ui.label.setText("You have selected Plus")

def multiplymessage(self):
self.ui.label.setText("You have selected Multiply")

def minusmessage(self):
self.ui.label.setText("You have selected Minus")

def dividemessage(self):
self.ui.label.setText("You have selected Divide")

def equalmessage(self):
self.ui.label.setText("You have selected Equal")

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
error message:
Error:
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> Traceback (most recent call last): File "C:\Users\Regan\Documents\inf1511\chapter10\calltoolbar.pyw", line 2, in <module> from toolbardemo import * File "C:\Users\Regan\Documents\inf1511\chapter10\toolbardemo.py", line 94, in <module> import tmpresource_rc ImportError: No module named 'tmpresource_rc'

I hope I did the code tags correctly
Reply
#4
(Aug-13-2017, 02:39 PM)red_man_008 Wrote: I hope I did the code tags correctly
Code tag is okay i fix error code tag,but there is no indentation.
Don't push any button before paste in code,paste in with Ctrl+Shift+v to avoid formatting problem.
When has paste in add code tag bye usingĀ  [Image: python.png]
Reply
#5
I am having trouble compiling a program which relates to main window and resource file with .ico files.

I suspect it has something to do with the location of the resource file, but this is just a guess.

Any help in this regard would be greatly appreciated

Thank you

.py file:
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'toolbardemo.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

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_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(800, 600)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(40, 40, 381, 16))
        self.label.setObjectName(_fromUtf8("label"))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)
        self.toolBar = QtGui.QToolBar(MainWindow)
        self.toolBar.setObjectName(_fromUtf8("toolBar"))
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
        self.actionPlus = QtGui.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/add.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionPlus.setIcon(icon)
        self.actionPlus.setObjectName(_fromUtf8("actionPlus"))
        self.actionMinus = QtGui.QAction(MainWindow)
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/minus.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionMinus.setIcon(icon1)
        self.actionMinus.setObjectName(_fromUtf8("actionMinus"))
        self.actionMultiply = QtGui.QAction(MainWindow)
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/multiply.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionMultiply.setIcon(icon2)
        self.actionMultiply.setObjectName(_fromUtf8("actionMultiply"))
        self.actionDivide = QtGui.QAction(MainWindow)
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/divide.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionDivide.setIcon(icon3)
        self.actionDivide.setObjectName(_fromUtf8("actionDivide"))
        self.actionEqual = QtGui.QAction(MainWindow)
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap(_fromUtf8(":/icon images/equals.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionEqual.setIcon(icon4)
        self.actionEqual.setObjectName(_fromUtf8("actionEqual"))
        self.toolBar.addAction(self.actionPlus)
        self.toolBar.addAction(self.actionMinus)
        self.toolBar.addAction(self.actionMultiply)
        self.toolBar.addAction(self.actionDivide)
        self.toolBar.addAction(self.actionEqual)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.label.setText(_translate("MainWindow", "TextLabel", None))
        self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar", None))
        self.actionPlus.setText(_translate("MainWindow", "Plus", None))
        self.actionPlus.setToolTip(_translate("MainWindow", "Plus", None))
        self.actionMinus.setText(_translate("MainWindow", "Minus", None))
        self.actionMinus.setToolTip(_translate("MainWindow", "Minus", None))
        self.actionMultiply.setText(_translate("MainWindow", "Multiply", None))
        self.actionMultiply.setToolTip(_translate("MainWindow", "Multiply", None))
        self.actionDivide.setText(_translate("MainWindow", "Divide", None))
        self.actionDivide.setToolTip(_translate("MainWindow", "Divide", None))
        self.actionEqual.setText(_translate("MainWindow", "Equal", None))
        self.actionEqual.setToolTip(_translate("MainWindow", "Equal", None))

import tmpresource.qrc
import sys
from toolbardemo import *

class MyForm(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.connect(self.ui.actionPlus, QtCore.SIGNAL('tiggered()'), self.plusmessage)
        self.connect(self.ui.actionMinus, QtCore.SIGNAL('tiggered()'), self.minusmessage)
        self.connect(self.ui.actionMultiply, QtCore.SIGNAL('tiggered()'), self.multiplymessage)
        self.connect(self.ui.actionDivide, QtCore.SIGNAL('tiggered()'), self.dividemessage)
        self.connect(self.ui.actionEqual, QtCore.SIGNAL('tiggered()'), self.equalmessage)

    def plusmessage(self):
        self.ui.label.setText("You have selected Plus")

    def multiplymessage(self):
        self.ui.label.setText("You have selected Multiply")

    def minusmessage(self):
        self.ui.label.setText("You have selected Minus")

    def dividemessage(self):
        self.ui.label.setText("You have selected Divide")

    def equalmessage(self):
        self.ui.label.setText("You have selected Equal")

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = MyForm()
    myapp.show()
    sys.exit(app.exec_())
error message:
above
Reply
#6
did you compile your Resource file(.qrc) by using pyrcc
pyrcc4 tmpresource.qrc -o tmpresource.py
On line 94 you have included tmpresource.qrc. you cant directly import it you first have to make .py file and import that.
Reply
#7
No, I did not convert the .qrc file.

I now converted it using pyrcc4 tmpresource.qrc -o tmpresource.py but then i got this error message

Quote:Traceback (most recent call last):
File "C:\Users\Regan\Documents\inf1511\chapter10\calltoolbar.pyw", line 2, in <module>
from toolbardemo import *
File "C:\Users\Regan\Documents\inf1511\chapter10\toolbardemo.py", line 94, in <module>
import tmpresource
File "C:\Users\Regan\Documents\inf1511\chapter10\tmpresource.py", line 1410, in <module>
qInitResources()
File "C:\Users\Regan\Documents\inf1511\chapter10\tmpresource.py", line 1405, in qInitResources
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
TypeError: qRegisterResourceData(int, str, str, str): argument 2 has unexpected type 'str'

I probably need to amend the .pyw file but I have no idea how
Reply
#8
No the problem is with resource file. Or maybe just the conversation. pyrcc generates python 2 code by default use -py3 to generate python 3 code.

[inline]
pyrcc4 -py3 tmpresource.qrc -o tmpresource.py
[/inline]
Reply
#9
it worked!!

thank you very very much
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] error message the_wolf_dz 4 1,945 Oct-24-2022, 07:24 PM
Last Post: deanhystad
  Error message box and quit app Kumarkv 1 2,216 May-19-2020, 07:05 PM
Last Post: Larz60+
  [Tkinter] How to make message box error stay on top of window scratchmyhead 1 8,121 May-10-2020, 10:21 PM
Last Post: scratchmyhead
  [PyQt] No reaction and no error message when clicking button Atalanttore 4 4,754 Nov-23-2018, 01:48 PM
Last Post: Atalanttore

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020