Hi Guys!

I'm hours trying to solve this code .... how do I close the first by window the X title bar button...popup and close together?

Obs: (I'm using PyQt4)



Qt Code:
  1. #!/usr/bin/env python
  2. #-*- coding: utf-8 -*-
  3.  
  4. import sys
  5. from PyQt4.QtGui import *
  6. from PyQt4.QtCore import *
  7.  
  8.  
  9. class Mainw(object):
  10. def __init__(self, MainWindow):
  11. super(Mainw, self).__init__()
  12.  
  13. self.cw = QWidget(MainWindow)
  14.  
  15. self.btn1 = QPushButton("Popup", self.cw)
  16. MainWindow.setCentralWidget(self.cw)
  17.  
  18. self.btn1.setGeometry(QRect(0, 0, 100, 30))
  19.  
  20.  
  21. QObject.connect(self.btn1, SIGNAL("clicked()"), self.openpopup)
  22.  
  23. def openpopup(self):
  24. self.pop = QWidget()
  25. self.pop.setGeometry(QRect(100, 100, 400, 200))
  26. self.pop.show()
  27.  
  28.  
  29.  
  30. if __name__ == "__main__":
  31. app = QApplication(sys.argv)
  32. MainWindow = QMainWindow()
  33. main = Mainw(MainWindow)
  34. MainWindow.show()
  35. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode