import sys from PySide6.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton from PySide6.QtGui import QPainter, QPen from PySide6.QtCore import Qt class CADWindow(QWidget): def __init__(self): super().__init__() self.setWindowTitle("CAD") self.resize(800, 600) # Create a label for the dimensions input self.dimension_label = QLabel("Dimensions:", self) self.dimension_label.move(10, 10) # Create a line edit for the user to enter the dimensions self.dimension_input = QLineEdit() self.dimension_input.setPlaceholderText("Enter dimensions...") self.dimension_input.setFixedWidth(300) self.dimension_input.move(10, 40) # Create a button for the user to confirm the dimensions self.confirm_button = QPushButton("Confirm", self) self.confirm_button.clicked.connect(self.confirm_dimensions) self.confirm_button.move(10, 70) # Create a label for the canvas self.canvas_label = QLabel("Canvas:", self) self.canvas_label.move(400, 10) # Create a canvas widget for the user to draw on self.canvas = QWidget() self.canvas.setFixedSize(300, 300) self.canvas.move(400, 40) # Set the default dimensions of the canvas self.dimensions = (300, 300) def confirm_dimensions(self): # Get the dimensions from the line edit and convert to a tuple dimensions = self.dimension_input.text().split(",") dimensions = [int(d) for d in dimensions] self.dimensions = dimensions # Resize the canvas widget to match the new dimensions self.canvas.setFixedSize(*self.dimensions) def paintEvent(self, event): # Get a painter object for painting on the canvas painter = QPainter(self.canvas) # Set the pen color and width painter.pen = QPen(Qt.black, 2) # Draw a line across the canvas using the dimensions from the user input painter.drawLine(0, 0, *self.dimensions) if __name__ == "__main__": app = QApplication(sys.argv) window = CADWindow() window.show() sys.exit(app.exec_())