-
Notifications
You must be signed in to change notification settings - Fork 2
/
file.py
48 lines (40 loc) · 1.88 KB
/
file.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
46
47
48
#-*- coding:utf-8 -*-
#######pyqt 文件载入对话框,文件保存对话框,打开文件夹对话框
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class MyWindow(QDialog,QWidget):
def __init__(self,parent = None):
super(MyWindow,self).__init__(parent)
self.resize(400,150)
self.mainlayout = QGridLayout(self)
self.loadFileButton = QPushButton()
self.loadFileButton.setText(u"载入文件")
self.mainlayout.addWidget(self.loadFileButton,0,0,1,1)
self.loadFileLineEdit = QLineEdit()
self.mainlayout.addWidget(self.loadFileLineEdit,0,1,1,4)
self.loadFileButton.clicked.connect(self.loadFile)
self.saveFileButton = QPushButton()
self.saveFileButton.setText(u"保存文件")
self.saveFileLineEdit = QLineEdit()
self.mainlayout.addWidget(self.saveFileButton,1,0,1,1)
self.mainlayout.addWidget(self.saveFileLineEdit,1,1,1,4)
self.saveFileButton.clicked.connect(self.saveFile)
self.openFileDirButton = QPushButton()
self.openFileDirButton.setText(u"打开文件目录")
self.mainlayout.addWidget(self.openFileDirButton,2,0,1,1)
self.openFileDirButton.clicked.connect(self.openFileDirectory)
def loadFile(self):########载入file
file_name = QFileDialog.getOpenFileName(self,"open file dialog","./home/fish","Txt files(*.txt)")
##"open file Dialog "文件对话框的标题,第二个是打开的默认路径,第三个是文件类型
self.loadFileLineEdit.setText(file_name)
def saveFile(self):
file_path = QFileDialog.getSaveFileName(self,'save file',"saveFile" ,"xj3dp files (*.xj3dp);;all files(*.*)") ####
print file_path
def openFileDirectory(self):
import os
os.popen("explorer.exe ./home/fish")
app=QApplication(sys.argv)
window=MyWindow()
window.show()
app.exec_()