所以我刚开始使用Qt4和pyqt将代码转换为python等等。我正在尝试创建各种计时器,但这并不重要。我在Qt中创建了gui并将其转换为python代码,添加了一些东西来运行代码,但是当我运行它时我仍然只是得到一个空白窗口,我创建的框的按钮都没有出现。任何想法??
感谢
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_())
答案 0 :(得分:2)
def _init_(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
您缺少init的双下划线,因此您的调用不会被调用。 它应该是:
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)