Hello,
I have created a basic application with a push button.
The objective is for a pop-up message box to show up when I click on the push button.
Based on the input provided in the push button , the program has to close.
import sys
from PyQt5.QtWidgets import QApplication,QWidget,QToolTip,QPushButton,QMessageBox
from PyQt5.QtGui import QFont
class Window(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def closeevent(self):
reply=QMessageBox.question(self,'Message','Are you sure you want to quit?',QMessageBox.Yes|QMessageBox.No,QMessageBox.No )
if reply==QMessageBox.Yes:
event.accept()
else:
event.ignore()
/
def initUI(self):
QToolTip.setFont(QFont('Arial',10,3))
self.setToolTip('This is <i>Window </i> Tooltip' )
btn1=QPushButton('Click here to close the pgm',self)
btn1.setToolTip('This is <i>Button </i> Tooltip')
btn1.resize(btn1.sizeHint())
btn1.clicked.connect(self.closeevent())
self.setGeometry(100,100,300,300)
self.show()
if __name__=="__main__":
app=QApplication(sys.argv)
obj1=Window()
sys.exit(app.exec_())
Have created a function called closeevent().
On click of the button , this function has to be called.
However when I call self.closeevent() like any other function,
The window shows only the message box and not the complete window.
Why is it so?
I have created a basic application with a push button.
The objective is for a pop-up message box to show up when I click on the push button.
Based on the input provided in the push button , the program has to close.
import sys
from PyQt5.QtWidgets import QApplication,QWidget,QToolTip,QPushButton,QMessageBox
from PyQt5.QtGui import QFont
class Window(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def closeevent(self):
reply=QMessageBox.question(self,'Message','Are you sure you want to quit?',QMessageBox.Yes|QMessageBox.No,QMessageBox.No )
if reply==QMessageBox.Yes:
event.accept()
else:
event.ignore()
/
def initUI(self):
QToolTip.setFont(QFont('Arial',10,3))
self.setToolTip('This is <i>Window </i> Tooltip' )
btn1=QPushButton('Click here to close the pgm',self)
btn1.setToolTip('This is <i>Button </i> Tooltip')
btn1.resize(btn1.sizeHint())
btn1.clicked.connect(self.closeevent())
self.setGeometry(100,100,300,300)
self.show()
if __name__=="__main__":
app=QApplication(sys.argv)
obj1=Window()
sys.exit(app.exec_())
Have created a function called closeevent().
On click of the button , this function has to be called.
However when I call self.closeevent() like any other function,
The window shows only the message box and not the complete window.
Why is it so?