菜菜菜菜几 2018-06-13 07:17 采纳率: 54.5%
浏览 2516
已采纳

帮我运行一下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条回答 默认 最新

  • stone178 2018-06-13 09:14
    关注

    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'

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead
  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数