pyqt open file dialog

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, \
    QPushButton, QVBoxLayout, QFileDialog

# you can copy and run this code

class MainWindow(QMainWindow):
    def __init__(self, parent=None):#--------------
        super(MainWindow, self).__init__(parent)#  |
        self.setWindowTitle("open file dialog")#   |
#												   |
        btn = QPushButton("Open File")#            |---- Just initialization
        layout = QVBoxLayout()#					   |
        layout.addWidget(btn)#                     |
        widget = QWidget()#                        |
        widget.setLayout(layout)#                  |
        self.setCentralWidget(widget)#-------------

        btn.clicked.connect(self.open) # connect clicked to self.open()
        self.show()

    def open(self):
        path = QFileDialog.getOpenFileName(self, 'Open a file', '',
                                        'All Files (*.*)')
        if path != ('', ''):
            print("File path : "+ path[0])

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    sys.exit(app.exec_())

3
1
Sarah L 65 points

                                    def open(self):
    path = QFileDialog.getOpenFileName(self, 'Open a file', '',
                                     'All Files (*.*)')
    if path != ('', ''):
		print(path[0])

3 (1 Votes)
0
3.8
10

                                    def open_file(self):
	def open(self):
        path = QFileDialog.getOpenFileName(self, 'Open a file', '',
                                        'All Files (*.*)')
        if path != ('', ''):
            print(path[0])

3.8 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
pyQT5 dialogue pyqt5 new dialog types pyqt5 new dialog what is ui dialog in pyqt5 open file dialog pyqt5 pyqt5 browse file dialog PyQt5 lunch dialog pyqt5 settings dialog pyqt5 save dialog pyqt5 open window to save dialog on button click show open file dialog and selet file in python pyqt5 pyqt5 open file dialog PyQt5 python create a dialog custom open dialog pyqt5 on button click opening dialog pyqt5 dialog button box pyqt5 pyqt5 dialog windows shows ? python import file dialog pyqt pyqt5 open file dialouge pyqt5 file dialog python pyqt5 dialog button box pyqt5 open file dialog button pyqt6 open new file dialog pyqt5 input dialog show dialog pyqt5 PyQt5 Dialogs pyqt file dialog image how to make choose file dialog in pyQt5 open file dialog pyqt6 dialog cloud in pyqt5 pyqt file dialog folder open file dialog box in pyqt5 pyqt5 open dialog from mainwindow python pyqt5 dialog box pyqt5 dialog box example pyqt5 dialog window pyqt5 dialog box with widgets file dialog in pyqt5 input dialog in pyqt5 PyQt5 Input Dialog examples pyqt file dialog finished() pyqt5 dialog pyqt5 Dialog pyqt5 create dialog pyqt5 file dialog directory how to create a dialog window in pyqt5 PyQT open file dialog example how to open file browser in python with pyqt5 pyqt5 choose file file open dialog in pyqt5 python pyqt file dialog save pyqt file dialog save with open pyqt save dialog with open set pqt file save dialog example python pyqt save dialog with open write pyqt save dialog dialog pyqt5 QFileDialog.getOpenFileName python pyqt5 browseslot file dialog file input pyqt5 pyqt qfiledialog example pyqt file search pyqt browse file open file pyqt oppen file pyqt QFileDialog pyqt file explorer pyqt python open file dialog pyqt5 pyqt file dialog python QFileDialog.getOpenFileName python qt.QFileDialog.getOpenFileName get file options pyqt5 QFileDialog widget example filedialog python pyqt5 qwidget pyqt5 python name of file file explorer pyqt5 dialog open file pyqt5 open file manager pyqt5 designer open file manager python pyqt5 designer open file manager python pyqt5 pyqt5 save file dialog how to open a file dialog in askopenfilename PyQt5 python how to add open file dialog in pyqt5 on button press filedialog in pyqt5 file selector in pyqt5 pyqt save file dialog how to open dialog box in pyqt5 file open in pyqt5 qfiledialog pyqt5 open file pyqt5 pyqt5 upload file qfiledialog example python file Dialog in pyqt5 designer? openfile pyqt pyqt5 file dialog pyqt5 file dialog example open file dialog on button click pyqt5 pyqt open file dialog
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source