pyqt 'Ui_Form' 对象没有属性 'show' [英] pyqt 'Ui_Form' object has no attribute 'show'

查看:191
本文介绍了pyqt 'Ui_Form' 对象没有属性 'show'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的填充此代码由 pyuic 生成我正在使用 pyqt4和 python 2.7

this is my fill this code is generated by pyuic im using pyqt4 and python 2.7

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'editgui.ui'
#
# Created: Mon Nov 24 17:33:07 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 PyQt4
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_Form(object):

    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.setEnabled(True)
        Form.resize(1032, 779)
        Form.setMinimumSize(QtCore.QSize(1032, 779))
        Form.setMaximumSize(QtCore.QSize(1032, 779))
        self.textEdit = QtGui.QTextEdit(Form)
        self.textEdit.setGeometry(QtCore.QRect(90, 110, 361, 221))
        self.textEdit.setObjectName(_fromUtf8("textEdit"))
        self.textEdit_2 = QtGui.QTextEdit(Form)
        self.textEdit_2.setGeometry(QtCore.QRect(90, 430, 361, 261))
        self.textEdit_2.setObjectName(_fromUtf8("textEdit_2"))
        self.lineEdit = QtGui.QLineEdit(Form)
        self.lineEdit.setGeometry(QtCore.QRect(90, 380, 361, 20))

...self.label_6.setGeometry(QtCore.QRect(510, 90, 46, 13))self.label_6.setObjectName(_fromUtf8("label_6"))

... self.label_6.setGeometry(QtCore.QRect(510, 90, 46, 13)) self.label_6.setObjectName(_fromUtf8("label_6"))

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.lineEdit_2, QtCore.SIGNAL(_fromUtf8("textChanged(QString)")), self.pushButton.show)
        QtCore.QObject.connect(self.textEdit, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.pushButton.show)
        QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL(_fromUtf8("textChanged(QString)")), self.pushButton.show)
        QtCore.QObject.connect(self.textEdit_2, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.pushButton.show)
        QtCore.QObject.connect(self.lineEdit_3, QtCore.SIGNAL(_fromUtf8("textChanged(QString)")), self.pushButton.show)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))
        self.label.setText(_translate("Form", "titel", None))
        self.label_2.setText(_translate("Form", "beschrijving", None))
        self.label_3.setText(_translate("Form", "frans", None))
        self.label_4.setText(_translate("Form", "titel", None))
        self.label_5.setText(_translate("Form", "beschrijving", None))
        self.pushButton.setText(_translate("Form", "save", None))
        self.pushButton_2.setText(_translate("Form", "run", None))
        self.label_6.setText(_translate("Form", "website", None))

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

这是我得到的错误

Traceback (most recent call last):
  File "C:\Users\IT4PROGRESS\Desktop\2dehands gui\output.py", line 99, in <module>
    ex.show
AttributeError: 'Ui_Form' object has no attribute 'show'

我使用 python 2.7

i use python 2.7

推荐答案

首先,不要编辑 pyuic 生成的文件.制作另一个 .py 文件并导入它.这样,您可以创建一个基于 QMainWindow 的类,您可以运行 show(),而不是尝试直接 show() 生成的 UI 文件> on,它将为您构建生成的 ui 文件.像这样:

Firstly, don't edit file generated by pyuic. Make another .py file and import it. That way, instead of trying to show() the generated UI file directly, you can make a QMainWindow based class that you can run show() on and it will build the generated ui file for you. Like this:

import sys
from PyQt4 import QtCore, QtGui
from Ui_Form import Ui_Form

class Main(QtGui.QMainWindow):
    def __init__(self):
        super(Main, self).__init__()

        # build ui
        self.ui = Ui_Form()
        self.ui.setupUi(self)

        # connect signals
        self.ui.some_button.connect(self.on_button)

    def on_button(self):
        print 'Button clicked!'


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

这篇关于pyqt 'Ui_Form' 对象没有属性 'show'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆