pyqt4 - python - cannot import name from file generated with pyuic4 -


i have following 2 scripts, first of generated using pyuic4 windows, , not modified.

textedit.py:

# -*- coding: utf-8 -*-  # form implementation generated reading ui file 'mytextedit.ui' # # created: mon sep 22 14:47:34 2014 #      by: pyqt4 ui code generator 4.11.2 # # warning! changes made in file lost!  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_notepad(object):     def setupui(self, notepad):         notepad.setobjectname(_fromutf8("notepad"))         notepad.resize(763, 638)         self.centralwidget = qtgui.qwidget(notepad)         self.centralwidget.setobjectname(_fromutf8("centralwidget"))         self.verticallayout_2 = qtgui.qvboxlayout(self.centralwidget)         self.verticallayout_2.setobjectname(_fromutf8("verticallayout_2"))         self.verticallayout = qtgui.qvboxlayout()         self.verticallayout.setobjectname(_fromutf8("verticallayout"))         self.tabwidget = qtgui.qtabwidget(self.centralwidget)         self.tabwidget.setmaximumsize(qtcore.qsize(16777215, 16777215))         self.tabwidget.settabshape(qtgui.qtabwidget.triangular)         self.tabwidget.settabsclosable(true)         self.tabwidget.setmovable(true)         self.tabwidget.setobjectname(_fromutf8("tabwidget"))         self.tab = qtgui.qwidget()         self.tab.setobjectname(_fromutf8("tab"))         self.verticallayout_3 = qtgui.qvboxlayout(self.tab)         self.verticallayout_3.setobjectname(_fromutf8("verticallayout_3"))         self.plaintextedit = qtgui.qplaintextedit(self.tab)         self.plaintextedit.setobjectname(_fromutf8("plaintextedit"))         self.verticallayout_3.addwidget(self.plaintextedit)         self.tabwidget.addtab(self.tab, _fromutf8(""))         self.tab_2 = qtgui.qwidget()         self.tab_2.setobjectname(_fromutf8("tab_2"))         self.tabwidget.addtab(self.tab_2, _fromutf8(""))         self.verticallayout.addwidget(self.tabwidget)         self.verticallayout_2.addlayout(self.verticallayout)         notepad.setcentralwidget(self.centralwidget)         self.menubar = qtgui.qmenubar(notepad)         self.menubar.setgeometry(qtcore.qrect(0, 0, 763, 21))         self.menubar.setobjectname(_fromutf8("menubar"))         self.menufile = qtgui.qmenu(self.menubar)         self.menufile.setobjectname(_fromutf8("menufile"))         self.menuedit = qtgui.qmenu(self.menubar)         self.menuedit.setobjectname(_fromutf8("menuedit"))         notepad.setmenubar(self.menubar)         self.statusbar = qtgui.qstatusbar(notepad)         self.statusbar.setobjectname(_fromutf8("statusbar"))         notepad.setstatusbar(self.statusbar)         self.actionnew = qtgui.qaction(notepad)         self.actionnew.setobjectname(_fromutf8("actionnew"))         self.actionopen = qtgui.qaction(notepad)         self.actionopen.setobjectname(_fromutf8("actionopen"))         self.actionsave = qtgui.qaction(notepad)         self.actionsave.setobjectname(_fromutf8("actionsave"))         self.actionsave_as = qtgui.qaction(notepad)         self.actionsave_as.setobjectname(_fromutf8("actionsave_as"))         self.actionpaste = qtgui.qaction(notepad)         self.actionpaste.setobjectname(_fromutf8("actionpaste"))         self.actioncut = qtgui.qaction(notepad)         self.actioncut.setobjectname(_fromutf8("actioncut"))         self.actioncopy = qtgui.qaction(notepad)         self.actioncopy.setobjectname(_fromutf8("actioncopy"))         self.actiondelete = qtgui.qaction(notepad)         self.actiondelete.setobjectname(_fromutf8("actiondelete"))         self.actiondelete_line = qtgui.qaction(notepad)         self.actiondelete_line.setobjectname(_fromutf8("actiondelete_line"))         self.actionselect_all_2 = qtgui.qaction(notepad)         self.actionselect_all_2.setobjectname(_fromutf8("actionselect_all_2"))         self.menufile.addaction(self.actionnew)         self.menufile.addaction(self.actionopen)         self.menufile.addaction(self.actionsave)         self.menufile.addaction(self.actionsave_as)         self.menuedit.addaction(self.actionpaste)         self.menuedit.addaction(self.actioncut)         self.menuedit.addaction(self.actioncopy)         self.menuedit.addaction(self.actiondelete)         self.menuedit.addaction(self.actiondelete_line)         self.menuedit.addaction(self.actionselect_all_2)         self.menubar.addaction(self.menufile.menuaction())         self.menubar.addaction(self.menuedit.menuaction())          self.retranslateui(notepad)         self.tabwidget.setcurrentindex(0)         qtcore.qmetaobject.connectslotsbyname(notepad)      def retranslateui(self, notepad):         notepad.setwindowtitle(_translate("notepad", "text edit", none))         self.tabwidget.settabtext(self.tabwidget.indexof(self.tab), _translate("notepad", "tab 1", none))         self.tabwidget.settabtext(self.tabwidget.indexof(self.tab_2), _translate("notepad", "tab 2", none))         self.menufile.settitle(_translate("notepad", "file", none))         self.menuedit.settitle(_translate("notepad", "edit", none))         self.actionnew.settext(_translate("notepad", "new", none))         self.actionnew.setshortcut(_translate("notepad", "ctrl+n", none))         self.actionopen.settext(_translate("notepad", "open", none))         self.actionopen.setshortcut(_translate("notepad", "ctrl+o", none))         self.actionsave.settext(_translate("notepad", "save", none))         self.actionsave.setshortcut(_translate("notepad", "ctrl+s", none))         self.actionsave_as.settext(_translate("notepad", "save as", none))         self.actionsave_as.setshortcut(_translate("notepad", "ctrl+shift+s", none))         self.actionpaste.settext(_translate("notepad", "paste", none))         self.actionpaste.setshortcut(_translate("notepad", "ctrl+v", none))         self.actioncut.settext(_translate("notepad", "cut", none))         self.actioncopy.settext(_translate("notepad", "copy", none))         self.actiondelete.settext(_translate("notepad", "delete", none))         self.actiondelete_line.settext(_translate("notepad", "delete line", none))         self.actionselect_all_2.settext(_translate("notepad", "select all", none)) 

start.py:

#! /usr/bin/env python3.4  import sys pyqt4 import qtcore, qtgui textedit import ui_notepad  class startqt4(qtgui.qmainwindow):     """docstring startqt4"""     def __init__(self, parent=none):         qtgui.qmainwindow.__init__(self, parent)         self.parent = parent         self.ui = ui_notepad()         self.ui.setupui(self)  if __name__ == '__main__':     app = qtgui.qapplication(sys.argv)     myapp = startqt4()     myapp.show()     sys.exit(app.exec_()) 

i have understanding of how importing works, whatever try error:

traceback (most recent call last):   file "e:\python\text editor\start.py", line 5, in <module>     textedit import ui_notepad importerror: cannot import name 'ui_notepad' 

you need lowercase i in from textedit import ui_notepad

you using from textedit import ui_notepad , class is:

class ui_notepad(object) <- i not i


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -