The simplest solution is to change your newLog to this
def NewLog(self):
app = QtGui.QWidget()
self.form = Ui_Form()
self.form.setupUi(app)
self.form.show()
with the self.form
defined in the Ui_mainwindow
class
class Ui_MainWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QMainWindow.__init__(self,parent)
self.form = None
In your code, you are defining the myapp = Ui_form()
variable inside of the newLog
function and then it is going out of scope and being deleted right when the function exits. If you were to somehow include some blocking of the function ending you wouldn't technically need to put self.form
in the __init__()
of Ui_mainWindow
. Say, for instance, you had a form that would return require a button hit to close, then you could just do it as you had it, but since you're just show()
ing a widget, you need to have it survive outside of the function.
Edit: For instance, this code would run just fine for the above stated reason--you have to click the button before the function exits
def NewLog(self, text='I am open!', buttons=QtGui.QMessageBox.Ok):
errorBox = QtGui.QMessageBox()
errorBox.setText(text)
errorBox.setStandardButtons(buttons)
return errorBox.exec_()