Python Forum
[PyQt] Popup window not coming
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Popup window not coming
#1
hi,
i am new to PyQt5. i am trying to make a GUI with the help of a tutorial. but popup window is not coming when i click the button

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import  QMessageBox
import sys

class Ui_ClickWindow(object):
    def setupUi(self, ClickWindow):
        ClickWindow.setObjectName("ClickWindow")
        ClickWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(ClickWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.button = QtWidgets.QPushButton(self.centralwidget)
        self.button.setGeometry(QtCore.QRect(70, 90, 641, 341))
        self.button.setIconSize(QtCore.QSize(40, 40))
        self.button.setObjectName("button")
        ClickWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(ClickWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName("menubar")
        ClickWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(ClickWindow)
        self.statusbar.setObjectName("statusbar")
        ClickWindow.setStatusBar(self.statusbar)

        self.retranslateUi(ClickWindow)
        QtCore.QMetaObject.connectSlotsByName(ClickWindow)

        self.button.clicked.connect(self.show_popup)
        
    def retranslateUi(self, ClickWindow):
        _translate = QtCore.QCoreApplication.translate
        ClickWindow.setWindowTitle(_translate("ClickWindow", "Click me"))
        self.button.setText(_translate("ClickWindow", "Press me"))

    def show_popup(self):
        msg = QMessageBox()
        msg.setWindowTitle("Lame")
        msg.setText("your computer is Lame. Thank you")
        msg.setIcon(QMessageBox.Warning)
        msg.standardButtons(QMessageBox.Ok|QMessageBox.Abort|QMessageBox.Ignore)
        x = msg.exec_()
        
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    ClickWindow = QtWidgets.QMainWindow()
    ui = Ui_ClickWindow()
    ui.setupUi(ClickWindow)
    ClickWindow.show()
    sys.exit(app.exec_())
buran write Dec-25-2024, 05:47 AM:
No BBcode Answer
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
in line 39 try

msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Abort | QMessageBox.Ignore)
Reply
#3
The issue might be with the button connection. Add a print() inside show_popup() to confirm if the method is triggered. If it’s not triggered, check your button’s signal connection.

Here’s the modified version:

def show_popup(self):
    print("Button clicked!")  # Check if triggered
    msg = QMessageBox()
    msg.setWindowTitle("Lame")
    msg.setText("your computer is Lame. Thank you")
    msg.setIcon(QMessageBox.Warning)
    msg.exec_()
If the print shows but no popup appears, check your environment or installation. If no print appears, verify the signal-slot connection.
buran write Jan-02-2025, 04:15 AM:
Spam link removed
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  popup, text input with two readable buttons ethompson 7 2,077 Aug-28-2024, 03:40 AM
Last Post: deanhystad
  [Tkinter] Tkinter popup no grabbing the selected keys - Event propagation Wehaveall 2 1,390 Aug-10-2024, 01:18 PM
Last Post: Wehaveall
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 2,640 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Error coming PKT 1 3,175 May-11-2023, 11:46 AM
Last Post: Axel_Erfurt
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 3,003 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft
  POPUP on widget Entry taratata2020 4 5,214 Mar-10-2020, 05:04 PM
Last Post: taratata2020
  tkinter window and turtle window error 1885 3 8,303 Nov-02-2019, 12:18 PM
Last Post: 1885
  [Tkinter] [SOLVED] Create per button popup menu py2.7 AceScottie 5 7,704 May-31-2018, 12:39 AM
Last Post: AceScottie
  popup message box code runs in Windows, but not in Linux Luke_Drillbrain 13 19,041 May-10-2017, 01:05 AM
Last Post: metulburr
  update a variable in parent window after closing its toplevel window gray 5 11,237 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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