在MainWindow中 出现弹窗 然后获取用户输入在弹窗lineedit里面的值
第一步:对QDialog
注意buttons
buttons = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel,
Qt.Horizontal,self)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
ok对应accept(), cancel对应reject()槽函数
在函数FolderName()中获取Lineedit内容:
def FolderName(self):
self.FolderName = self.lineedit.text()
if self.FolderName:
return self.FolderName
# else:
# QMessageBox.warning(self, "Warning", "=======please input a folder name!",
# QMessageBox.Cancel)
第二:在MainWindow中
self.NewFolderDialog = GetFolderName.GetFolderName()
if self.NewFolderDialog.exec_():
self.NewFolderName = str(self.NewFolderDialog.FolderName())
self.NewFolderDialog.destroy()
通过exec_()显示执行dialog
如果self.NewFolderName没有值 返回的None
if self.NewFolderName == "None" :
QMessageBox.warning(self,"Warning","please input a folder name!",
QMessageBox.Cancel)
else:
print("===========NewFolderName")
print(self.NewFolderName)