Kyle Mathew Joeckel Kyle Mathew Joeckel - 5 months ago 16
Python Question

Cant get program to run correctly Python/Qt/PyQt

So i am just starting out using Qt4 and pyqt to convert the code to python and so on. I am trying to create a timer of sorts but that doesn't really matter. I've created the gui in Qt and converted it to python code, added a few things to get the code running, but when i run it i still just get a blank window, none of the buttons of boxes that i created are showing up. any ideas??

thanks

import sys
import time
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_Dialog(QtGui.QWidget):
def _init_(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)

def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(160, 183)
self.gridLayout = QtGui.QGridLayout(Dialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.countInput = QtGui.QLineEdit(Dialog)
self.countInput.setObjectName(_fromUtf8("countInput"))
self.gridLayout.addWidget(self.countInput, 2, 0, 1, 1)
self.timeView = QtGui.QLCDNumber(Dialog)
self.timeView.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
self.timeView.setDigitCount(5)
self.timeView.setObjectName(_fromUtf8("timeView"))
self.gridLayout.addWidget(self.timeView, 2, 1, 1, 1)
self.startButton = QtGui.QPushButton(Dialog)
self.startButton.setObjectName(_fromUtf8("startButton"))
self.gridLayout.addWidget(self.startButton, 3, 0, 1, 1)
self.stopButton = QtGui.QPushButton(Dialog)
self.stopButton.setAutoDefault(True)
self.stopButton.setDefault(True)
self.stopButton.setObjectName(_fromUtf8("stopButton"))
self.gridLayout.addWidget(self.stopButton, 3, 1, 1, 1)
self.progressLbl = QtGui.QLabel(Dialog)
self.progressLbl.setText(_fromUtf8(""))
self.progressLbl.setAlignment(QtCore.Qt.AlignCenter)
self.progressLbl.setObjectName(_fromUtf8("progressLbl"))
self.gridLayout.addWidget(self.progressLbl, 4, 0, 1, 2)

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

def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.startButton.setText(_translate("Dialog", "Start", None))
self.stopButton.setText(_translate("Dialog", "Stop", None))


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

Answer

    def _init_(self):
        QtGui.QWidget.__init__(self)
        self.setupUi(self)

You are missing the double underscores for the init, so yours isn't getting called. It should be:


    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.setupUi(self)
Comments