菜菜菜菜几 2018-06-13 02:13 采纳率: 54.5%
浏览 5737
已结题

Qt designer设计菜单,打开文件对话框,编写好逻辑后,点击打开文件,没弹出对话框,且程序退出

界面文件:

-*- 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

逻辑文件:
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():
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_())

  • 写回答

3条回答

  • qq_37582886 2018-06-13 02:44
    关注

    我遇到过这种情况,开机重新试一下

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题