我想从文本文件中读取一行数据并在“文本编辑”框中显示该数据
It's quite simple, actually:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
FILENAME = 'textedit_example.py'
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.edit = QTextEdit()
layout = QVBoxLayout()
layout.addWidget(self.edit)
self.setLayout(layout)
self.edit.setText("No file found")
with open(FILENAME) as f:
self.edit.setText(f.readline())
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
Some notes:
import sys
) You may interest to look at this tutorial
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.