Friday 15 February 2013

importing and running generated pyqt gui in python is not working -



importing and running generated pyqt gui in python is not working -

i'm new python , pyqt well. i'm using canopy python editor.

i have designed simple gui using qt designer (version 5) including 2 buttons , graphicsview. converted using pyuic python file called themaingui followings:

from pyqt4 import qtcore, qtgui try: _fromutf8 = qtcore.qstring.fromutf8 except attributeerror: def _fromutf8(s): homecoming s try: _encoding = qtgui.qapplication.unicodeutf8 def _translate(context, text, disambig): homecoming qtgui.qapplication.translate(context, text, disambig, _encoding) except attributeerror: def _translate(context, text, disambig): homecoming qtgui.qapplication.translate(context, text, disambig) class ui_mainwindow(object): def setupui(self, mainwindow): mainwindow.setobjectname(_fromutf8("mainwindow")) mainwindow.resize(467, 268) self.centralwidget = qtgui.qwidget(mainwindow) self.centralwidget.setobjectname(_fromutf8("centralwidget")) self.fetchbutton = qtgui.qpushbutton(self.centralwidget) self.fetchbutton.setgeometry(qtcore.qrect(30, 40, 111, 31)) self.fetchbutton.setobjectname(_fromutf8("fetchbutton")) self.plotbutton = qtgui.qpushbutton(self.centralwidget) self.plotbutton.setgeometry(qtcore.qrect(30, 120, 111, 31)) self.plotbutton.setobjectname(_fromutf8("plotbutton")) self.graphicsview = qtgui.qgraphicsview(self.centralwidget) self.graphicsview.setgeometry(qtcore.qrect(190, 10, 256, 192)) self.graphicsview.setobjectname(_fromutf8("graphicsview")) mainwindow.setcentralwidget(self.centralwidget) self.menubar = qtgui.qmenubar(mainwindow) self.menubar.setgeometry(qtcore.qrect(0, 0, 467, 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.retranslateui(mainwindow) qtcore.qmetaobject.connectslotsbyname(mainwindow) def retranslateui(self, mainwindow): mainwindow.setwindowtitle(_translate("mainwindow", "mainwindow", none)) self.fetchbutton.settext(_translate("mainwindow", "fetch user data", none)) self.plotbutton.settext(_translate("mainwindow", "plot user track", none))

i want import gui code python file add together functionality gui. don't want edit same gui python file since might need alter while implementing , erase code.

therefore, created python file including next code:

import sys pyqt4 import qtgui themaingui import ui_mainwindow class main(qtgui.qmainwindow,ui_mainwindow): def __int__(self): qtgui.qmainwindow.__init__(self) self.ui= ui_mainwindow() self.ui.setupui(self) if __name__ == "__main__": app = qtgui.qapplication(sys.argv) window = main() window.show() sys.exit(app.exec_())

this code working tutorials found online. but, when run it, shows empty window without title.

i spent much time trying figure out what's wrong code without progress. help much appreciated.

python pyqt enthought qt-designer canopy

No comments:

Post a Comment