Python Forum
[PyQt] Close program using Push Button with the help of input from a Message Box
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Close program using Push Button with the help of input from a Message Box
#1
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?
Reply


Messages In This Thread
Close program using Push Button with the help of input from a Message Box - by bhargavbn - Oct-25-2018, 08:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - touchscreen, push the button like click the mouse John64 5 951 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 5,176 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas? Osman_P 4 5,375 Nov-14-2020, 10:51 AM
Last Post: Osman_P
  [Tkinter] Open a python program from a button Pedroski55 3 5,087 Jul-20-2020, 11:09 PM
Last Post: Pedroski55
  [Tkinter] How to close all windows when exit program scratchmyhead 3 6,498 May-17-2020, 08:19 AM
Last Post: menator01
  [Tkinter] Creating a restart button for a Pythagorean Theorem Program pav1983 12 7,378 Apr-21-2020, 07:25 AM
Last Post: pav1983
  [PyQt] Push Button issue gvin47 8 4,404 Apr-18-2020, 05:39 PM
Last Post: deanhystad
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,071 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Windows GUI with push buttons to launch python scripts drifterf 7 4,248 Jul-17-2019, 05:34 PM
Last Post: Yoriz
  Text after push button chano 13 5,509 Jul-05-2019, 03:10 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020