Python用户界面不工作。
我已使用pyuic4将.ui文件转换为.py文件。但是当我用python运行代码时,什么都没有发生。没有错误,没有用户界面。代码在一秒钟内运行并结束。我尝试使用print命令进行调试,python没有进入def setupUiself,Frame:或def retranslateUiself,Frame: 我做错了什么?谢谢你的帮助Python用户界面不工作。,python,qt-designer,pyuic,Python,Qt Designer,Pyuic,我已使用pyuic4将.ui文件转换为.py文件。但是当我用python运行代码时,什么都没有发生。没有错误,没有用户界面。代码在一秒钟内运行并结束。我尝试使用print命令进行调试,python没有进入def setupUiself,Frame:或def retranslateUiself,Frame: 我做错了什么?谢谢你的帮助 # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'web
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'web.ui'
#
# Created: Mon Dec 29 08:39:41 2014
# by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import sys
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_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName(_fromUtf8("Frame"))
Frame.resize(562, 525)
Frame.setFrameShape(QtGui.QFrame.StyledPanel)
Frame.setFrameShadow(QtGui.QFrame.Raised)
self.webView = QtWebKit.QWebView(Frame)
self.webView.setGeometry(QtCore.QRect(0, 60, 561, 461))
self.webView.setUrl(QtCore.QUrl(_fromUtf8("about:blank")))
self.webView.setObjectName(_fromUtf8("webView"))
self.pushButton = QtGui.QPushButton(Frame)
self.pushButton.setGeometry(QtCore.QRect(460, 20, 75, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.lineEdit = QtGui.QLineEdit(Frame)
self.lineEdit.setGeometry(QtCore.QRect(70, 30, 351, 20))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.retranslateUi(Frame)
QtCore.QMetaObject.connectSlotsByName(Frame)
def retranslateUi(self, Frame):
Frame.setWindowTitle(_translate("Frame", "Frame", None))
self.pushButton.setText(_translate("Frame", "PushButton", None))
from PyQt4 import QtWebKit
添加以下内容:
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
f=QtGui.QMainWindow()
w = Ui_MainWindow()
w.setupUi(f)
f.show()
sys.exit(app.exec_())
我知道您已经定义了几个函数,但是您似乎没有调用它们中的任何一个。请记住:除非调用函数,否则函数不会执行任何操作。错误之处在于未能阅读PyQt文档:例如。