python pyqt5 点击按钮打开窗体

-- coding: utf-8 --

Form implementation generated from reading ui file 'D:\file\python\siflask\test.ui'

Created by: PyQt5 UI code generator 5.11.3

WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QApplication , QMainWindow import sys

class Ui_PUsh(object): def setupUi(self, PUsh): PUsh.setObjectName("PUsh") PUsh.resize(541, 489) self.pushButton = QtWidgets.QPushButton(PUsh) self.pushButton.setGeometry(QtCore.QRect(150, 140, 171, 51)) self.pushButton.setObjectName("pushButton") self.openfile = QtWidgets.QPushButton(PUsh) self.openfile.setGeometry(QtCore.QRect(150, 250, 181, 71)) self.openfile.setObjectName("openfile") self.actionopenfile = QtWidgets.QAction(PUsh) self.actionopenfile.setObjectName("actionopenfile")

    self.retranslateUi(PUsh)
    self.pushButton.clicked.connect(PUsh.close)
    self.openfile.clicked.connect(PUsh.openfilea)
    QtCore.QMetaObject.connectSlotsByName(PUsh)

def retranslateUi(self, PUsh):
    _translate = QtCore.QCoreApplication.translate
    PUsh.setWindowTitle(_translate("PUsh", "Form"))
    self.pushButton.setText(_translate("PUsh", "PushButton"))
    self.openfile.setText(_translate("PUsh", "openfile"))
    self.actionopenfile.setText(_translate("PUsh", "openfile"))

def openfilea(self, PUsh):
    file,ok=QtWidgets.QFileDialog.getOpenFileName(self,"打开","C:/","ALL Files (*);;Text Files (*.exe)")
    print(file)

class MyMainWindow(QMainWindow, Ui_PUsh): def init(self, parent=None): super(MyMainWindow, self).init(parent) self.setupUi(self)

if name == "main": app = QApplication(sys.argv) myWin = MyMainWindow() myWin.show() sys.exit(app.exec_())

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券