我正在用python开发一些程序。现在我可以打开第二个窗口,但现在我将回到我的第一个窗口。我的问题是当我按下关闭按钮时,我的第一个和第二个窗口关闭。我会只关闭我的第二个窗口。
我的代码: import sys from PyQt4 import QtCore, QtGui from forms.runtime_form import Ui_runtime_form import datetime import time
"""
The main class
First window
"""
class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
self.run_mode = 0
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_runtime_form()
self.ui.setupUi(self)
self.main_thread = main_thread(self)
self.main_thread.start()
self.main_thread.update_date_time.connect(self.update_date_time)
if self.run_mode == 0:
Uit = QtGui.QPushButton('Uit', self)
Uit.move(20,650)
Uit.clicked.connect(QtCore.QCoreApplication.instance().quit)
#button to open second window
bla = QtGui.QPushButton('bla', self)
bla.move(150,650)
bla.clicked.connect(self.child)
#open second window
def child(self):
test = Example(self)
test.showFullScreen()
def update_date_time(self):
#some other code
#Second window
class Example(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
Uit = QtGui.QPushButton('Uit', self)
Uit.clicked.connect(self.sluit)
Uit.move(150,50)
self.setGeometry(300, 300, 500, 150)
self.setWindowTitle('Modbus Domotica - Touchscreen')
self.show()
#Close second window
def sluit(self):
sys.exit(0)
class main_thread(QtCore.QThread):
update_date_time = QtCore.pyqtSignal()
def __init__(self, layout):
QtCore.QThread.__init__(self)
def __del__(self):
self.wait()
def run(self):
while True:
self.update_date_time.emit()
time.sleep(10)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create("Cleanlooks"))
QtGui.QApplication.setPalette(QtGui.QApplication.style().standardPalette())
myapp = StartQT4()
myapp.showFullScreen()
sys.exit(app.exec_())