Bottom Page

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_())

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 276 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  General help with hide show status bar for a begineer in python ArakelTheDragon 0 293 Mar-17-2019, 11:58 AM
Last Post: ArakelTheDragon
  How to show graph as a slideshow in PyQt5 using matplotlib binsha 0 769 Mar-08-2019, 03:58 AM
Last Post: binsha
  Hide button when clicked frequency 2 435 Dec-24-2018, 02:10 PM
Last Post: frequency
  [PyQt] Can't show PyQt5 mediaPlayer in window DecaK 1 975 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 1,394 Jun-12-2018, 08:05 AM
Last Post: Larz60+
  Show GPG keys in pyqt5 window Fred Barclay 1 1,846 Oct-24-2016, 07:09 PM
Last Post: micseydel
  Hide command window sparkz_alot 8 8,513 Sep-29-2016, 10:14 AM
Last Post: wavic

Forum Jump:


Users browsing this thread: 1 Guest(s)