current position:Home>pyqt5,python
pyqt5,python
2022-06-24 09:02:09【CSDN Q & A】
pyqt5
Attach completed untiled.py Code
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'untitled.ui'## Created by: PyQt5 UI code generator 5.13.0## WARNING! All changes made in this file will be lost!import osfrom PyQt5 import QtCore, QtGui, QtWidgetsimport sysfrom PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialogclass Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(340, 220, 93, 28)) self.pushButton.setObjectName("pushButton") self.pushButton2 = QtWidgets.QPushButton(self.centralwidget) self.pushButton2.setGeometry(QtCore.QRect(340, 250, 93, 28)) self.pushButton2.setObjectName("pushButton2") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.pushButton.clicked.connect(self.pbClicked) self.pushButton2.clicked.connect(self.pbClicked2) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.pushButton.setText(_translate("MainWindow", "PushButton")) self.pushButton2.setText(_translate("MainWindow", "PushButton2")) def pbClicked(self): self.fileName = QFileDialog.getOpenFileNames(None, " Please select the file to add ", "E:\Program Files (x86)\PycharmProjects\nn\wangyiyun", "Text Files (*.xls);;All Files (*)") return self.fileName def pbClicked2(self): os.system('python test2.py')if __name__=='__main__': app=QApplication(sys.argv) mainWindow=QMainWindow() ui=Ui_MainWindow() # You need to change your name ui.setupUi(mainWindow) mainWindow.show() sys.exit(app.exec_())
def pbClicked(self): self.fileName = QFileDialog.getOpenFileNames(None, " Please select the file to add ", "E:\Program Files (x86)\PycharmProjects\nn\wangyiyun", "Text Files (*.xls);;All Files (*)") return self.fileName
I was thinking about this filename This variable can be passed to another py In the document , And can output
def pbClicked(self): self.fileName = QFileDialog.getOpenFileNames(None, " Please select the file to add ", "E:\Program Files (x86)\PycharmProjects\nn\wangyiyun", "Text Files (*.xls);;All Files (*)") return self.fileNamedef pbClicked2(self): os.system('python test2.py')
Just click the second button , And then run test2.py file , And then in test2.py In the file, you can get the file path returned by the first button to open the file
Here is test2.py
import Qtdesigner.untitled as tsfrom Qtdesigner.untitled import Ui_MainWindowfilename = Ui_MainWindow.pbClicked()print(filename)
But this Ui_MainWindow.pbClicked(), Report errors Parameter 'self' unfilled
copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/175/202206171620074723.html
The sidebar is recommended
- Writing sample code for functions in Python
- Summary of operation methods of Python set (about 20 operation methods), with sample code attached
- Python -- functions
- Anonymous and recursive functions in Python
- How to query the methods (member functions) of a class or an object in Python [using the function dir()]
- Summary of operation methods of Python Dictionary (dict) (about 18 operation methods), with sample code attached
- Collect hot search lists in Python at work, which can be called a fishing artifact
- Running Django and Vue on docker
- Data classification in pandas
- About Python: docxtpl is embedded by default when inserting pictures
guess what you like
How to solve the problem of CSV? (Language Python)
Installation and use of redis (Python)
Python implements sending mail (implements single / group mail verification code)
On the built-in object type of Python -- number (one of the differences between py2 and PY3)
Python God uses a problem to help you solve the problems of formal and actual parameters in Python functions
"Project Euler Python Mini tutorial" 001-010 solution introduction
Most beginners learn Python and web automation. In this way, they learn and give up
Python matrices and numpy arrays
Exciting challenge: Python crawler crawls the cover picture of station B
After installing python3, use the yum command to report an error?
Random recommended
- New features of python3.6, 3.7, 3.8 and 3.9
- Application of Python simplehttpserver
- Python sending mail (single / group) - yagmail module
- After learning these English words, mom doesn't have to worry that I can't learn Python any more
- 1-python+ selenium automated test (detailed tutorial) in the series of exercises of "teach you by hand"
- Cannot unmarshal array into go value of type main
- Analysis of the principle of Python import
- Python quickly saves pictures in wechat official account articles (multiple articles can be specified)
- Python error reporting series (14) -- selenium support for phantom JS has been deprecated
- Python variable data type
- Advanced Python Programming - functions and modules
- Python conditional judgment and loop statements
- Python dictionary nesting
- I want to use Python to write a census management software. I want to ask about the ideas and software involved
- I want to use Python to write a census management software. I want to consult the ideas and software involved.
- Python program has no idea
- How to set the initial position of the cursor in Python Tkinter
- The scrapy framework only gets a set of results. I don't know why (Language Python)
- Code problems in Python
- Python automation framework
- Vscode - offline extension installation tutorial (take Python plug-in installation as an example)
- _ What are the application scenarios in Python
- Python writing yaml file
- On the strange phenomenon of Python objects
- System learning Python -- unit test unittest: Test Report
- Learn Python in this way, and the boss licks back the resume in the trash can: 25K per month
- Guess the age of American mathematician Wiener
- Python machine learning day03
- Random seed()
- Programming science | you may be wrong about Python
- Is Python really worth learning
- What is the charm of python, which is warmly pursued by countless programmers?
- Python is popular for several reasons: These data tell you
- Picture to character drawing in Python, so easy!
- Data type conversion in pandas module
- Python Basics - (1) overview of Python
- Data Science Library Python -- learning of time series data
- Django project - error reporting
- [run the script framework in Django and store the data in the database]
- Complete Python exception handling in ten minutes