-
Notifications
You must be signed in to change notification settings - Fork 2
/
readtxt.py
36 lines (29 loc) · 1.03 KB
/
readtxt.py
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
31
32
33
34
35
36
#!/usr/bin/python
# openfiledialog.py
import sys
from PyQt4 import QtGui, QtCore
class OpenFile(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('OpenFile')
self.textEdit = QtGui.QTextEdit()
self.setCentralWidget(self.textEdit)
self.statusBar()
self.setFocus()
exit = QtGui.QAction(QtGui.QIcon('icons/open.png'), 'Open', self)
exit.setShortcut('Ctrl+O')
exit.setStatusTip('Open new file')
self.connect(exit, QtCore.SIGNAL('triggered()'), self.showDialog)
menubar = self.menuBar()
file = menubar.addMenu('&File')
file.addAction(exit)
def showDialog(self):
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file', './')
file = open(filename)
data = file.read()
self.textEdit.setText(data)
app = QtGui.QApplication(sys.argv)
cd = OpenFile()
cd.show()
sys.exit(app.exec_())