0
안녕하세요 저는 GUI를 실험하고있는 학생입니다. 간단한 로그인 양식을 만드는 Python으로 작업 중이었고 기본 레이아웃을 만들 때 해결할 수없는 오류가 발생했습니다 변수. 이 코드입니다 :PyQt4에서 어떻게 창문을 시작합니까?
Traceback (most recent call last):
File "C:\Users\todd7\Desktop\PY_auth\design.py", line 75, in <module>
main()
File "C:\Users\todd7\Desktop\PY_auth\design.py", line 28, in main
w = Ui_Dialog(__init__)
NameError: name '__init__' is not defined
와 내가 얼마나 확실하지 않다 : 정렬이 내가 스택 오버 플로우하지만, 다음과 같은 출력의 코드 결과를 사용하는 데 사용하고 있지 않다 꺼져 있으면
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)
def main():
app = QtGui.QApplication(sys.argv)
w = Ui_Dialog(__init__)
w.show()
sys.exit(app.exec_())
class Ui_Dialog(object):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.addWidgets()
self.setupUi(self)
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(380, 272)
Dialog.setMinimumSize(QtCore.QSize(380, 272))
Dialog.setMaximumSize(QtCore.QSize(380, 272))
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setCenterButtons(True)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.user_name = QtGui.QTextEdit(Dialog)
self.user_name.setGeometry(QtCore.QRect(110, 50, 221, 31))
self.user_name.setAutoFillBackground(False)
self.user_name.setObjectName(_fromUtf8("user_name"))
self.user_pass = QtGui.QTextEdit(Dialog)
self.user_pass.setGeometry(QtCore.QRect(110, 120, 221, 31))
self.user_pass.setAutoFillBackground(False)
self.user_pass.setObjectName(_fromUtf8("user_pass"))
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(20, 60, 81, 21))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(20, 120, 81, 21))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.label.setText(_translate("Dialog", "USER NAME", None))
self.label_2.setText(_translate("Dialog", "PASSWORD", None))
if __name__ == "__main__":
main()
죄송합니다 문제를 해결할 수 있습니다.
, 당신의
main()
기능에,다음 , 그것은 막 뒤에서 불렀다. 'w = Ui_Dialog (__ init __)'대신'w = Ui_Dialog()'를 시도하십시오. – 101
나는 당신이 제안한 것을 수행했으며 응답은'Traceback (가장 최근의 마지막 통화) : 파일 "C : \ Users \ todd7 \ Desktop \ PY_auth \ design.py"의 75 행 main() 파일 "C : \ Users \ todd7 \ Desktop \ PY_auth \ design.py", 줄 28, 주 w : Ui_Dialog() 파일 "C : \ Users \ in __init__ QtGui.QMainWindow .__ init __ (self, parent) TypeError : 설명 자 '__init__'에 'sip.simplewrapper'개체가 필요하지만 'Ui_Dialog'개체가 수신되었습니다. –