Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtWidgets import QApplication, QWidget, QTreeView, QFileSystemModel, QVBoxLayout
  3. from PyQt5.QtCore import QModelIndex
  4.  
  5. class FileSystemView(QWidget):
  6. def __init__(self, dir_path):
  7. super().__init__()
  8. appWidth = 800
  9. appHeight = 300
  10. self.setWindowTitle('File System Viewer')
  11. self.setGeometry(300, 300, appWidth, appHeight)
  12.  
  13. self.model = QFileSystemModel()
  14. self.model.setRootPath(dir_path)
  15. self.tree = QTreeView()
  16. self.tree.setModel(self.model)
  17. self.tree.setRootIndex(self.model.index(dirPath))
  18. self.tree.setColumnWidth(0, 250)
  19. self.tree.setAlternatingRowColors(True)
  20.  
  21. layout = QVBoxLayout()
  22. layout.addWidget(self.tree)
  23. self.setLayout(layout)
  24.  
  25. if __name__ == '__main__':
  26. app = QApplication(sys.argv)
  27. dirPath = r'<Your directory'
  28. demo = FileSystemView(dirPath)
  29. demo.show()
  30. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement