我在PyQt中编写此代码,但是当我尝试打开文件时,我收到此错误:
setNativeLocks失败:资源暂时不可用
为什么我无法打开并保存文件?
# class Main
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(300, 300))
self.setWindowTitle("TP1")
# Create new action
openAction = QAction(QIcon('open.png'), '&Open', self)
openAction.setShortcut('Ctrl+O')
openAction.setStatusTip('Open document')
openAction.triggered.connect(self.openCall)
# Save new action
saveAction = QAction(QIcon('save.png'), '&Save', self)
saveAction.setShortcut('Ctrl+S')
saveAction.setStatusTip('Save document')
saveAction.triggered.connect(self.newSave)
# Copy new action
copyAction = QAction(QIcon('copy.png'), '&Copy', self)
copyAction.setShortcut('Ctrl+C')
copyAction.setStatusTip('Copy document')
copyAction.triggered.connect(self.CopyCall)
# Create exit action
exitAction = QAction(QIcon('quit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.exitCall)
# Create menu bar and add action
menuBar = self.menuBar()
fileMenu = menuBar.addMenu('&File')
fileMenu.addAction(openAction)
fileMenu.addAction(saveAction)
fileMenu.addAction(copyAction)
fileMenu.addAction(exitAction)
def openCall(self):
fileName = QFileDialog.getOpenFileName(self,"Open Image","/home/m1/icheva/a","*.txt")
print('Open')
def newSave(self):
fileName1 = QFileDialog.getSaveFileName(self,"Save File","/home/m1/icheva/a/savefile.txt","*.txt")
print('Save ')
def CopyCall(self):
print('Copy app')
def exitCall(self):
print('Exit app')
#main
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit( app.exec_() )