Answers for "pyqt5 file dialog example"

0

pyqt5 file dialog example

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_())
Posted by: Guest on December-05-2020
0

pyqt open file dialog

def open_file(self):
	def open(self):
        path = QFileDialog.getOpenFileName(self, 'Open a file', '',
                                        'All Files (*.*)')
        if path != ('', ''):
            print(path[0])
Posted by: Guest on December-05-2020
0

open file dialog on button click pyqt5

def open(self):
    path = QFileDialog.getOpenFileName(self, 'Open a file', '',
                                     'All Files (*.*)')
    if path != ('', ''):
		print(path[0])
Posted by: Guest on December-05-2020

Python Answers by Framework

Browse Popular Code Answers by Language