-
Notifications
You must be signed in to change notification settings - Fork 0
/
DQVT_WINDOW_ver.py
45 lines (32 loc) · 1.18 KB
/
DQVT_WINDOW_ver.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
37
38
39
40
41
42
43
44
45
## Ex 6-4. QFileDialog.
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit, QAction, QFileDialog, QPushButton
from PyQt5.QtGui import QIcon
class MyApp(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.textEdit = QTextEdit()
self.setCentralWidget(self.textEdit)
self.statusBar()
openFile = QAction(QIcon('open.png'), 'Open', self)
openFile.setShortcut('Ctrl+O')
openFile.setStatusTip('Open New File')
openFile.triggered.connect(self.showDialog)
menubar = self.menuBar()
menubar.setNativeMenuBar(False)
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(openFile)
btn1 = QPushButton()
self.setWindowTitle('File Dialog')
self.setGeometry(300, 300, 300, 200)
self.show()
def showDialog(self):
fname = QFileDialog.getOpenFileName(self, 'Open file', './')
if fname[0]:
self.textEdit.setText(fname[0])
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())