这是我的view.py文件的代码,我现在正面临问题。
from PyQt6.QtWidgets import QMainWindow, QTextEdit, QFileDialog, QApplication, QScrollArea, QPlainTextEdit from PyQt6.QtGui import QTextCursor, QAction, QKeySequence class TextView: def __init__(self, parent=None): self.editor = QPlainTextEdit() self.window = QMainWindow() self.text_edit = QTextEdit() self.text_edit.textChanged.connect(self.text_changed) self.editor.setLineWrapMode(self.editor.WidgetWidth) self.window.setCentralWidget(self.text_edit) self.exit_action = QAction("Exit", self.window) self.exit_action.setShortcut(QKeySequence.Quit) self.exit_action.triggered.connect(self.window.close) self.window.addAction(self.exit_action) self.text_changed = False def text_changed(self): self.textChanged = True def load_text(self, file_path): with open(file_path, 'rt') as file: text = file.read() self.text_edit.setPlainText(text) def save_text(self, file_path): with open(file_path, 'wt') as file: text = self.text_edit.toPlainText() file.write(text)
我的设备是m1 macbook air,IDE是pycharm
我当前面临的错误是AttributeError: 'QPlainTextEdit' object has no attribute 'WidgetWidth'
尽快需要帮助
我试图查看文档,但我发现QPlainTextEdit确实具有该属性,但对我来说,它不起作用。