import sys
from PyQt5 import QtCore, QtGui, QtWidgets#, uic
from PyQt5.QtWidgets import (QFileDialog, QTreeView, QPushButton, QGridLayout,
QSpacerItem, QColorDialog, QAbstractItemView)
class MyWindow(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
self.setWindowTitle("Save ..")
self.resize(500, 500)
gridlayout = QGridLayout()
#uic.loadUi('gui.ui', self)
#self.connect(self.multiPackerAddDirsBtn, QtCore.SIGNAL('clicked()'), self.multiPackerAddDirs)
self.button1 = QPushButton("File")
self.button2 = QPushButton("Font")
self.button3 = QPushButton("Color")
gridlayout.addWidget(self.button1)
gridlayout.addWidget(self.button2)
gridlayout.addWidget(self.button3)
spacer = QSpacerItem(200, 80)
gridlayout.addItem(spacer, 3, 1, 1, 3)
#self.setLayout(gridlayout)
self.button1.clicked.connect(self.onButton1)
self.button1.clicked.connect(self.onButton2)
self.button1.clicked.connect(self.multiPackerAddDirs())
def onButton1(self):
fileName = QFileDialog.getOpenFileName(self, 'open')
if not fileName.isEmpty():
print fileName
self.setWindowTitle(fileName)
def onButton2(self):
font, ok = QFontDialog.getFont()
if ok:
self.setWindowTitle(font.key())
def onButton3(self):
color = QColorDialog.getColor()
if color.isValid():
self.setWindowTitle(color.name())
def multiPackerAddDirs(self):
#不依赖父窗口时: fileName = QFileDialog.getSaveFileName(None, u'save', "图片", u"Image(*png)")
fileName = QFileDialog.getSaveFileName(self, u'save', "图片", u"Image(*png)")print fileName
self.setWindowTitle(fileName)
dialog = QFileDialog(self)
dialog.setAcceptMode(AcceptSave)
dialog.setFileMode(QFileDialog.Directory)
dialog.setOption(QFileDialog.ShowDirsOnly, True)
dialogTreeView = dialog.findChild(QTreeView)
dialogTreeView.setSelectionMode(
QAbstractItemView.ExtendedSelection)
if dialog.exec_():
for dirname in dialog.selectedFiles():
self.multiPackerDirList.addItem(str(dirname))
print(str(dirname))
app = QtWidgets.QApplication(sys.argv)
mywindow = MyWindow()
mywindow.show()
app.exec_()