Python Forum
[PYQT5] Crashing when using .hide() and .show()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PYQT5] Crashing when using .hide() and .show()
#1
My program opens a main window with an investigation button, once that is clicked a second window opens and the first one is hidden.
The second window has a button and when it is clicked it is suppose to hide, however, it crashes.
If I run the second window by itself, not going through the first window, I can click the button and that window will hide. So I'm not sure why they're not working together.
Test.py

 from PyQt5 import QtCore, QtGui, QtWidgets
from Test2 import *

class Ui_MainWindow(object):
    def ipDombtn(self):
        self.window=QtWidgets.QMainWindow()
        self.ui=Ui_MainWindow1()
        self.ui.setup(self.window)
        self.window.show()


    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(412, 440)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")



        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout.addWidget(self.pushButton)
        self.pushButton.clicked.connect(self.ipDombtn)


        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 412, 31))
        self.menubar.setObjectName("menubar")

        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)


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


    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "Investigation"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())  
Test2.py

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow1(object):

    def exIpDomInv_clicked(self):
        print("You clicked a button...")





    def setup(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(412, 440)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")


        self.exIpDomInv = QtWidgets.QPushButton(self.centralwidget)
        self.exIpDomInv.setObjectName("exIpDomInv")
        self.verticalLayout.addWidget(self.exIpDomInv)


        MainWindow.setCentralWidget(self.centralwidget)
        self.Menu = QtWidgets.QMenuBar(MainWindow)
        self.Menu.setGeometry(QtCore.QRect(0, 0, 412, 31))
        self.Menu.setObjectName("Menu")

        MainWindow.setMenuBar(self.Menu)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")

        MainWindow.setStatusBar(self.statusbar)

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

        self.exIpDomInv.clicked.connect(self.exIpDomInv_clicked)



    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Investigation"))
        MainWindow.setAccessibleName(_translate("MainWindow", "InvestigationMenu"))
        self.exIpDomInv.setText(_translate("MainWindow", "External IP/ Domain Investigation"))



if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow1 = QtWidgets.QMainWindow()
    ui2 = Ui_MainWindow1()
    ui2.setup(MainWindow1)
    MainWindow1.show()
    sys.exit(app.exec_())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Hide clicked buttons Rubberduck 6 3,387 Jun-02-2021, 12:44 PM
Last Post: Rubberduck
  [PyQt] Crashing When Request Math Equation CharlieSchuyler 1 1,908 May-18-2020, 07:32 AM
Last Post: Axel_Erfurt
  [PyQt] Hide Dock Icon for QSystemTrayIcon App AeglosGreeenleaf 0 3,248 Jun-20-2019, 07:21 PM
Last Post: AeglosGreeenleaf
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,777 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  General help with hide show status bar for a begineer in python ArakelTheDragon 0 2,741 Mar-17-2019, 11:58 AM
Last Post: ArakelTheDragon
  How to show graph as a slideshow in PyQt5 using matplotlib binsha 0 3,863 Mar-08-2019, 03:58 AM
Last Post: binsha
  Hide button when clicked frequency 2 8,635 Dec-24-2018, 02:10 PM
Last Post: frequency
  [PyGUI] Hi All, how to hide/mask user input in PySimpleGUI nmrt 1 14,806 Sep-21-2018, 09:59 AM
Last Post: nmrt
  [PyQt] Can't show PyQt5 mediaPlayer in window DecaK 1 5,311 Sep-15-2018, 09:54 AM
Last Post: Axel_Erfurt
  [Tkinter] How to show and hide tkinter entry box when select yes from drop down Prince_Bhatia 1 10,432 Jun-12-2018, 08:05 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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