[PyQt] Help to run my sample PyQt program

John R johnrim20 at gmail.com
Mon Apr 13 07:02:40 BST 2015


Hello All,

I have created a UI file in Qtcreator and converted to python using pyuic.
after conversion I added following code blocks into this new python file
for PySide execution I had added number of widgets like buttons, radio
buttons, textboxes etc. and it run in Qt creator fine but after pyuic
conversion I could see only plain blank screen!!, could anyone please tell
me, where I have made wrong code. I have tried to run in Tkinter and
QtCreator (via Tools --> External --> Python ---> RunPy), both Tkinter and
Qt creator showing output only blank GUI

*Please note the modified code blocks*


*Code Block Added 1:*

import sys
from PySide import QtCore, QtGui


*Code Block Added 2:*

class ControlMainWindow(QtGui.QMainWindow):
 def init(self, parent=None):
     super(ControlMainWindow, self).init(parent)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    mySW = ControlMainWindow()
    mySW.show()
    sys.exit(app.exec_())




*Full code is below*


import sys
from PySide 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 MainWindow (QtGui.QMainWindow):

    def __init__ (self, parent = None):
        super (MainWindow, self).__init__ ()
        self.ui = Ui_MainWindow ()
        self.ui.setupUi (self)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(615, 338)
        MainWindow.setAutoFillBackground(False)
        MainWindow.setStyleSheet(_fromUtf8("background-color:
rgb(0,200,21);"))
        self.centralWidget = QtGui.QWidget(MainWindow)
        self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
        self.pushButton = QtGui.QPushButton(self.centralWidget)
        self.pushButton.setGeometry(QtCore.QRect(270, 80, 61, 23))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.checkBox = QtGui.QCheckBox(self.centralWidget)
        self.checkBox.setGeometry(QtCore.QRect(120, 40, 70, 17))
        self.checkBox.setObjectName(_fromUtf8("checkBox"))
        self.radioButton = QtGui.QRadioButton(self.centralWidget)
        self.radioButton.setGeometry(QtCore.QRect(230, 40, 82, 17))
        self.radioButton.setObjectName(_fromUtf8("radioButton"))
        self.radioButton_2 = QtGui.QRadioButton(self.centralWidget)
        self.radioButton_2.setGeometry(QtCore.QRect(290, 40, 82, 17))
        self.radioButton_2.setObjectName(_fromUtf8("radioButton_2"))
        self.label = QtGui.QLabel(self.centralWidget)
        self.label.setGeometry(QtCore.QRect(20, 40, 61, 16))
        self.label.setObjectName(_fromUtf8("label"))
        self.formLayoutWidget = QtGui.QWidget(self.centralWidget)
        self.formLayoutWidget.setGeometry(QtCore.QRect(120, 130, 261, 131))
        self.formLayoutWidget.setObjectName(_fromUtf8("formLayoutWidget"))
        self.formLayout = QtGui.QFormLayout(self.formLayoutWidget)

self.formLayout.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow)
        self.formLayout.setMargin(0)
        self.formLayout.setObjectName(_fromUtf8("formLayout"))
        self.radioButton_3 = QtGui.QRadioButton(self.formLayoutWidget)
        self.radioButton_3.setObjectName(_fromUtf8("radioButton_3"))
        self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole,
self.radioButton_3)
        self.checkBox_2 = QtGui.QCheckBox(self.formLayoutWidget)
        self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
        self.formLayout.setWidget(1, QtGui.QFormLayout.FieldRole,
self.checkBox_2)
        self.toolButton = QtGui.QToolButton(self.formLayoutWidget)
        self.toolButton.setObjectName(_fromUtf8("toolButton"))
        self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole,
self.toolButton)
        MainWindow.setCentralWidget(self.centralWidget)
        self.menuBar = QtGui.QMenuBar(MainWindow)
        self.menuBar.setGeometry(QtCore.QRect(0, 0, 615, 21))
        self.menuBar.setObjectName(_fromUtf8("menuBar"))
        MainWindow.setMenuBar(self.menuBar)
        self.mainToolBar = QtGui.QToolBar(MainWindow)
        self.mainToolBar.setObjectName(_fromUtf8("mainToolBar"))
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
        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.pushButton.setText(_translate("MainWindow", "Submit", None))
        self.checkBox.setText(_translate("MainWindow", "Scale", None))
        self.radioButton.setText(_translate("MainWindow", "Mesh", None))
        self.radioButton_2.setText(_translate("MainWindow", "Plot", None))
        self.label.setText(_translate("MainWindow", "Enter Values", None))
        self.radioButton_3.setText(_translate("MainWindow", "RadioButton",
None))
        self.checkBox_2.setText(_translate("MainWindow", "CheckBox", None))
        self.toolButton.setText(_translate("MainWindow", "...", None))


class ControlMainWindow(QtGui.QMainWindow):
 def init(self, parent=None):
     super(ControlMainWindow, self).init(parent)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    mySW = ControlMainWindow()
    mySW.show()
    sys.exit(app.exec_())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150413/60301453/attachment.html>


More information about the PyQt mailing list