Z15111823643
菜菜菜菜几
采纳率54.5%
2018-06-13 02:13 浏览 5.1k

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

5

界面文件:

-*- 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 qq_37582886 2018-06-13 02:44

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

    点赞 评论 复制链接分享
  • Z15111823643 菜菜菜菜几 2018-06-13 03:14

    所有用qt designer设计界面后,添加逻辑的程序都没办法响应,只是一个界面,无法点击

    点赞 评论 复制链接分享
  • wzh2529 wzh2529 2018-06-13 07:38

    应该是你的信号没设置对吧

    点赞 评论 复制链接分享

相关推荐