일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- 자동블로그
- 쿠파스
- 그누보드
- Javascript
- 챗지피티
- 아두이노 초보
- Ajax
- ChatGPT
- 쿠팡파트너스
- 프로그램
- 아두이노 강좌
- HTML
- 아두이노
- flex
- 자동글쓰기
- 워드프레스
- 파싱
- c#
- cocos2d-x
- 무료일러스트
- 자바스크립트
- 파이썬
- 웹
- Python
- 자동포스팅
- php
- 아두이노 기초강좌
- Php공부
- 쿠팡자동포스팅
- 쿠팡 블로그
- Today
- Total
플밍
파일 다이얼로그 본문
파일 열기 대화상자 예제
#ads_1
# -*- coding: utf-8 -*-
import sys
import codecs
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QMenuBar, QAction, QTextEdit
from PyQt5.QtGui import QIcon
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
fileAction = QAction(QIcon("icon.png"), "&Open", self)
fileAction.setShortcut('Ctrl+O')
fileAction.triggered.connect(self.showDialog)
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(fileAction)
self.textedit = QTextEdit(self)
self.setCentralWidget(self.textedit)
self.statusBar()
self.setGeometry(300,300,300,300)
self.setWindowTitle('File Window')
self.show()
def showDialog(self, e):
filepath = QFileDialog.getOpenFileName(self, 'Open File', 'd:')
if filepath[0]:
# 일반 open 으로 열었을 경우 아래와 같은 인코딩 에러가 나온다
# UnicodeDecodeError: 'cp949' codec can't decode bytes in position
fp = codecs.open(filepath[0], 'r', 'utf-8')
with fp:
buf = fp.read()
self.textedit.setText(buf)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
#ads_2