Hi small problem here that holding me up, I am using PYQT4
I am trying to call a second window from my QMainWindow, but I keep getting AttributeError: exec_
This is a very basic example of what I am trying to do.
One mainwindow with a pushbutton designed with Qt Designer,
and a second dialog window with a couple of pushbuttons in it also designed in Qt Designer.
both windows are set to ApplicationModal,
I used pyuic4 to convert the .ui files to .py files,
When the pushbutton is pressed the local function 'hit' tries to load to second window.
Files are attached.
Any help appreciated.
Cheers Richard
My start.py looks like this,
import sys
import MySQLdb
from PyQt4 import QtCore, QtGui, QtSql
from main import Ui_MainWindow
from dialog import Ui_Dialog
from PyQt4.QtGui import *
from PyQt4.QtCore import *
def __init__(self, parent=None):
QtGui.
QWidget.__init__
(self, parent
) self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.
QObject.
connect(self.
ui.
pushButton, QtCore.
SIGNAL("clicked()"), self.
hit)
def hit(self):
print 'hit'
dia = dialog1()
dia.show()
dia.exec_()
def __init__(self, parent=None):
QtGui.
QWidget.__init__
(self, parent
) self.di = Ui_Dialog()
self.di.setupUi(self)
if __name__ == "__main__":
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())
import sys
import MySQLdb
from PyQt4 import QtCore, QtGui, QtSql
from main import Ui_MainWindow
from dialog import Ui_Dialog
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.hit)
def hit(self):
print 'hit'
dia = QtGui.QWidget()
dia = dialog1()
dia.show()
dia.exec_()
class dialog1(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.di = Ui_Dialog()
self.di.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks