Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23189

Draw a Maze with PySide6

$
0
0

I have a binary file like this :

0 S 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 0 0 G 0 0 0 0 0 0 0 

The words "S" and "G" are represented as "Start" and "Goal", also zeros are represented as walls and ones are open. I wanna create something like this maze sample pictureI'v generated some piece of code with PySide6 library for at least basics, but I don't know why it doesn't show up anything even that(I just wanna show up the walls first), I'm sure that I missed something but I don't know what that is

import sysfrom PySide6.QtWidgets import QApplication, QMainWindow, QGraphicsScene, QGraphicsView, QGraphicsRectItemfrom PySide6.QtGui import QPen, QBrushfrom PySide6.QtCore import Qtclass MazeWindow(QMainWindow):    def __init__(self, maze):        super().__init__()        self.maze = maze        self.initUI()    def initUI(self):        self.setWindowTitle('Maze Visualizer')        self.setGeometry(100, 100, 600, 600)        scene = QGraphicsScene()        view = QGraphicsView(scene, self)        view.setGeometry(0, 0, 600, 600)        pen = QPen(Qt.black)        brush = QBrush(Qt.black)        cell_size = 50        for i, row in enumerate(self.maze):            for j, cell in enumerate(row):                if cell == '0':                    rect = QGraphicsRectItem(j * cell_size, i * cell_size, cell_size, cell_size)                    rect.setPen(pen)                    rect.setBrush(brush)                    scene.addItem(rect)        self.setCentralWidget(view)def main():    maze = [    # 0 S 0 0 0 0 0 0 0 0     ['0', 'S', '0', '0', '0', '0', '0', '0', '0', '0'],    # 1 1 1 0 0 0 1 0 1 1     ['1', '1', '1', '0', '0', '0', '1', '0', '1', '1'],    # 1 0 1 1 1 1 1 0 0 1     ['1', '0', '1', '1', '1', '1', '1', '0', '0', '1'],    # 0 1 0 0 0 1 1 1 1 1     ['0', '1', '0', '0', '0', '1', '1', '1', '1', '1'],    # 1 1 1 1 0 1 0 1 1 0     ['1', '1', '1', '1', '0', '1', '0', '1', '1', '0'],    # 0 1 0 1 1 1 0 1 0 1    ['0', '1', '0', '1', '1', '1', '0', '1', '0', '1'],    # 1 1 0 0 1 1 1 0 1 1    ['1', '1', '0', '0', '1', '1', '1', '0', '1', '1'],    # 0 0 1 1 0 0 1 1 0 0     ['0', '0', '1', '1', '0', '0', '1', '1', '0', '0'],    # 0 1 1 1 1 1 1 1 1 1     ['0', '1', '1', '1', '1', '1', '1', '1', '1', '1'],    # 0 0 G 0 0 0 0 0 0 0     ['0', '0', 'G', '0', '0', '0', '0', '0', '0', '0']    ]    app = QApplication(sys.argv)    window = MazeWindow(maze)    window.show()    app.exec()if __name__ == '__main__':    main()

so grateful for your advises.


Viewing all articles
Browse latest Browse all 23189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>