pyqt5 打开文件
来源:互联网 发布:vb游戏代码大全 编辑:程序博客网 时间:2024/05/21 09:04
import sysimport osfrom PyQt5.QtCore import *from PyQt5.QtWidgets import *class Notepad(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): openAction = QAction('Open', self) openAction.setShortcut('Ctrl+O') openAction.setStatusTip('Open a file') openAction.triggered.connect(self.openFile) closeAction = QAction('Close', self) closeAction.setShortcut('Ctrl+Q') closeAction.setStatusTip('Close Notepad') closeAction.triggered.connect(self.close) menubar = self.menuBar() fileMenu = menubar.addMenu('&File') fileMenu.addAction(openAction) fileMenu.addAction(closeAction) self.textEdit = QTextEdit(self) self.textEdit.setFocus() self.textEdit.setReadOnly(True) self.resize(700, 800) self.setWindowTitle('Notepad') self.setCentralWidget(self.textEdit) self.show() def openFile(self): filename, _ = QFileDialog.getOpenFileName(self, 'Open File', os.getenv('HOME')) fh = '' if QFile.exists(filename): fh = QFile(filename) if not fh.open(QFile.ReadOnly): QtGui.qApp.quit() data = fh.readAll() codec = QTextCodec.codecForUtfText(data) unistr = codec.toUnicode(data) tmp = ('Notepad: %s' % filename) self.setWindowTitle(tmp) self.textEdit.setText(unistr)def main(): app = QApplication(sys.argv) notepad = Notepad() sys.exit(app.exec_())if __name__ == '__main__': main()
0 0
- pyqt5 打开文件
- PyQt5打开文件对话框QFileDialog
- pyqt5 实现 下拉菜单 + 打开文件
- PyQt5学习笔记09----标准文件打开保存框QFileDialog
- PyQt5学习教程16:文件打开对话框的使用
- pyqt5 窗口文件示范
- PyQt5:QFileDialog文件对话框(22)
- 170326 PyQt5-复习、文件操作
- PyQt5
- pyqt5
- pyqt5中使用QtDesigner生成ui文件
- 打开路径打开文件
- 打开文件
- 打开文件
- 打开文件
- 文件打开
- 打开文件
- 打开文件
- Linux常用命令总结
- C编译器剖析_Github
- dubbo框架中一行日志代码引发的超时问题
- 消息队列RabbitMQ与Spring
- Android使用百度地图开发时,出现定位无反应。log里出现162错误代码
- pyqt5 打开文件
- 最佳调度问题 Time Limit:10000MS Memory Limit:65536K Total Submit:89 Accepted:36 Case Time Limit:1000MS
- [leetcode] 394. Decode String
- 学习笔记之JavaSE(49)--网络编程1
- php 不常见的读取文件的方法
- UVa 1151 Buy or Build
- 贝塞尔曲线
- postgreSQL的实用程序
- iOS 开发缓存机制之一内存缓存机制