帮我运行一下PYQT5的界面代码,点击菜单中的打开,看是否弹出文件对话框

文件1: jiemian1.py

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

# Form implementation generated from reading ui file 'jiemian1.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
        self.menubar.setObjectName("menubar")
        self.menu_F = QtWidgets.QMenu(self.menubar)
        self.menu_F.setObjectName("menu_F")
        self.menu_E = QtWidgets.QMenu(self.menubar)
        self.menu_E.setObjectName("menu_E")
        self.menu_V = QtWidgets.QMenu(self.menubar)
        self.menu_V.setObjectName("menu_V")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.toolBar = QtWidgets.QToolBar(MainWindow)
        self.toolBar.setObjectName("toolBar")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
        self.fileOpenAction = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/tubiao/open.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.fileOpenAction.setIcon(icon)
        self.fileOpenAction.setObjectName("fileOpenAction")
        self.fileNewAction = QtWidgets.QAction(MainWindow)
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(":/tubiao/new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.fileNewAction.setIcon(icon1)
        self.fileNewAction.setObjectName("fileNewAction")
        self.fileCloseAction = QtWidgets.QAction(MainWindow)
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(":/tubiao/close.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.fileCloseAction.setIcon(icon2)
        self.fileCloseAction.setObjectName("fileCloseAction")
        self.addWinaction = QtWidgets.QAction(MainWindow)
        self.addWinaction.setObjectName("addWinaction")
        self.menu_F.addAction(self.fileOpenAction)
        self.menu_F.addAction(self.fileNewAction)
        self.menu_F.addAction(self.fileCloseAction)
        self.menu_E.addSeparator()
        self.menubar.addAction(self.menu_F.menuAction())
        self.menubar.addAction(self.menu_E.menuAction())
        self.menubar.addAction(self.menu_V.menuAction())
        self.toolBar.addAction(self.addWinaction)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "声学包数据库系统"))
        self.menu_F.setTitle(_translate("MainWindow", "文件(F)"))
        self.menu_E.setTitle(_translate("MainWindow", "编辑(E)"))
        self.menu_V.setTitle(_translate("MainWindow", "视图(V)"))
        self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar"))
        self.fileOpenAction.setText(_translate("MainWindow", "打开"))
        self.fileOpenAction.setShortcut(_translate("MainWindow", "Alt+O"))
        self.fileNewAction.setText(_translate("MainWindow", "新建"))
        self.fileNewAction.setShortcut(_translate("MainWindow", "Alt+C"))
        self.fileCloseAction.setText(_translate("MainWindow", "关闭"))
        self.fileCloseAction.setShortcut(_translate("MainWindow", "Alt+C"))
        self.addWinaction.setText(_translate("MainWindow", "添加窗体"))

import ICON_rc

文件2:calljiemian1.py

import sys
from PyQt5.QtWidgets import *
from jiemian1 import Ui_MainWindow

class MainForm(QMainWindow,Ui_MainWindow):
        def __init__(self):
            super(MainForm,self).__init__()
            self.setupUi(self)
            self.fileCloseAction.triggered.connect(self.close)
            self.fileOpenAction.triggered.connect(self.openMsg)

        def openMsg():
            print(1)
            file,ok= QFileDialog.getOpenFileName(self,"打开","E:\声学包数据库\声学包\界面测试数据","All Files (*);;Text Files (*.txt)")
            self.statusbar.showMessage(file)
if __name__=="__main__":
    app= QApplication(sys.argv)
    win= MainForm()
    win.show()
    sys.exit(app.exec_())



1个回答

D:>python --version
Python 3.5.1

D:>python jiemian1.py
Traceback (most recent call last):
File "jiemian1.py", line 78, in
import ICON_rc
ImportError: No module named 'ICON_rc'

D:>python calljiemian1.py
Traceback (most recent call last):
File "calljiemian1.py", line 3, in
from jiemian1 import Ui_MainWindow
File "D:\jiemian1.py", line 78, in
import ICON_rc
ImportError: No module named 'ICON_rc'

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问