Open a second window in PyQt

前端 未结 3 677
野趣味
野趣味 2021-02-02 01:23

I\'m trying to use pyqt to show a custom QDialog window when a button on a QMainWindow is clicked. I keep getting the following error:

$ python main.py 
DEBUG:          


        
3条回答
  •  被撕碎了的回忆
    2021-02-02 02:05

    I've done like this in the past, and i can tell it works. assuming your button is called "Button"

    class Main(QtGui.QMainWindow):
        ''' some stuff '''
        def on_Button_clicked(self, checked=None):
            if checked==None: return
            dialog = QDialog()
            dialog.ui = Ui_MyDialog()
            dialog.ui.setupUi(dialog)
            dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
            dialog.exec_()
    

    This works for my application, and I believe it should work with yours as well. hope it'll help, it should be pretty straight forward to do the few changes needed to apply it to your case. have a good day everybody.

提交回复
热议问题