Last active
March 27, 2024 03:39
-
-
Save DataSolveProblems/6e37710831d9a1f42f9f8375cd914642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5.QtWidgets import QApplication, QWidget, QTreeView, QFileSystemModel, QVBoxLayout | |
from PyQt5.QtCore import QModelIndex | |
class FileSystemView(QWidget): | |
def __init__(self, dir_path): | |
super().__init__() | |
appWidth = 800 | |
appHeight = 300 | |
self.setWindowTitle('File System Viewer') | |
self.setGeometry(300, 300, appWidth, appHeight) | |
self.model = QFileSystemModel() | |
self.model.setRootPath(dir_path) | |
self.tree = QTreeView() | |
self.tree.setModel(self.model) | |
self.tree.setRootIndex(self.model.index(dirPath)) | |
self.tree.setColumnWidth(0, 250) | |
self.tree.setAlternatingRowColors(True) | |
layout = QVBoxLayout() | |
layout.addWidget(self.tree) | |
self.setLayout(layout) | |
if __name__ == '__main__': | |
app = QApplication(sys.argv) | |
dirPath = r'<Your directory>' | |
demo = FileSystemView(dirPath) | |
demo.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment