python - PyQt5 - Clicking Cancel on QFileDialog Closes Application -


i've noticed that, using following code, if choose click "cancel" on filedialog "import file", entire application closes instead of returning menu , awaiting different choice. how can return mainmenu?

(note: i've noticed if don't put after initial file dialog call, functions fine.)

code:

import sys import xml.etree.elementtree et pyqt5.qtwidgets import * pyqt5.qtgui import *   class mainmenu(qdialog):     def __init__(self):         qdialog.__init__(self)         layout = qgridlayout()          # create objects main menu         logolabel = qlabel("testapp")         logofont = qfont("broadway", 48)         logolabel.setfont(logofont)         versionlabel = qlabel("version 0.1a")         copyrightlabel = qlabel("copyright 2016")         importbutton = qpushbutton("import file")         quitbutton = qpushbutton("quit")          # set locations of widgets         layout.addwidget(logolabel, 0, 0)         layout.addwidget(versionlabel, 1, 0)         layout.addwidget(copyrightlabel, 2, 0)         layout.addwidget(importbutton, 4, 0)         layout.addwidget(quitbutton, 5, 0)         self.setlayout(layout)         self.setwindowtitle("nessql")          # connect buttons actions         importbutton.clicked.connect(self.importfile)         quitbutton.clicked.connect(self.close)      def importfile(self):         # open dialog box filename         file = qfiledialog.getopenfilename(self, caption="file import", directory=".",                                            filter="all files (*.*)")         data = et.parse(file)         root = data.getroot()   if __name__ == '__main__':     app = qapplication(sys.argv)     mainmenu = mainmenu()     mainmenu.show()     app.exec_() 


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -