How to close a window and open a new window with a button click?How to hide close button in WPF window?How to prevent a dialog from closing when a button is clickedGetting a Blank Progress bar window pyqt 5Cannot close Dialog on Python PyQt4PyQt5 Having trouble opening up multiple windows of the same applicationmultiple gui python qt and switch between themHow to stop second PyQt5 QMainWindow from closing?PyQt5 - Close QDialog window with cancel buttonDynamically add rows and columns in QTable in pyQT5PyQt - How to link and update the label from edit Window to my main window

Is this artwork (used in a video game) real?

what relax command means?

Can a Resident Assistant be told to ignore a lawful order?'

Is the purpose of sheet music to be played along to? Or a guide for learning and reference during playing?

Is straight-up writing someone's opinions telling?

Did Voldemort kill his father before finding out about Horcruxes?

What is the point of a constraint expression on a non-templated function?

Pi 3 B+ no audio device found

How would you say "Sorry, that was a mistake on my part"?

Why is Katakana not pronounced Katagana?

Why does "git status" show I'm on the master branch and "git branch" does not in a newly created repository?

Alphanumeric Line and Curve Counting

Which GPUs to get for Mathematical Optimization (if any...)?

Does this sentence I constructed with my junior high school latin work? I write online advertising and want to come off as snobby as possible

Optimising the Selection of MaxValue in Association

What happens if a company buys back all of its shares?

Did 007 exist before James Bond?

How could an animal "smell" carbon monoxide?

How to color a tag in a math equation?

Why did Steve Rogers choose this character in Endgame?

Increasing muscle power without increasing volume

Use chown -R while excluding one or two files

Is it rude to refer to janitors as 'floor people'?

How can the electric potential be zero at a point where the electric field isn't, if that field can give a test charge kinetic energy?



How to close a window and open a new window with a button click?


How to hide close button in WPF window?How to prevent a dialog from closing when a button is clickedGetting a Blank Progress bar window pyqt 5Cannot close Dialog on Python PyQt4PyQt5 Having trouble opening up multiple windows of the same applicationmultiple gui python qt and switch between themHow to stop second PyQt5 QMainWindow from closing?PyQt5 - Close QDialog window with cancel buttonDynamically add rows and columns in QTable in pyQT5PyQt - How to link and update the label from edit Window to my main window






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm creating a program with PyQt5 and have made to .py files for two windows. One is a logIn window and the other is the mainWindow. To open the program a separate program, main.py, will call a subroutine in the logInWindow.py to open that window up. There is a button there that when clicked is supposed to close the logIn window and open up the mainWindow.py by calling it. The main window opens up fine but the logIn window doesn't close. I need it so that the logIn window closes once the mainWindow is open. It doesn't matter if it does it before, during or after the mainWindow is open but as long as it does. I also need to be able to pass a value from the logInWindow to the mainWindow because of other parts of the program. I've made a simplified version of the code below.



I tried using things such as QtWidgets.QDialog().close() (which were recognised by the code) but didn't actually do anything. The only thing that closed it was sys.exit() but that shut the whole thing down before the line code to open the mainWindow.



#main.py
import logInWindow

var1 = input("Start: ")
if var1 == 'y':
logInWindow.openUp()


#logInWindow.py
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import mainWindow

class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 135)
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(110, 50, 161, 32))
self.pushButton.setBaseSize(QtCore.QSize(161, 32))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.buttonClick)

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

def buttonClick(self):
#code to close logInWindow here
needsToBePassed = 'This is the main window.'
mainWindow.openUp2(needsToBePassed)

def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "logInWindow"))
self.pushButton.setText(_translate("Dialog", "open mainWindow"))

def openUp():
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())


#mainWindow.py
from PyQt5 import QtCore, QtGui, QtWidgets
import sys

def openUp2(passed):
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(110, 130, 151, 16))
self.label.setObjectName("label")

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

def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "mainWindow"))
self.label.setText(_translate("Dialog", passed))

Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.exec_()


If anyone could help me out that'd be great! Also if it's a few lines of code instead of changing how the code works, that'd be better but either would do.










share|improve this question




























    0















    I'm creating a program with PyQt5 and have made to .py files for two windows. One is a logIn window and the other is the mainWindow. To open the program a separate program, main.py, will call a subroutine in the logInWindow.py to open that window up. There is a button there that when clicked is supposed to close the logIn window and open up the mainWindow.py by calling it. The main window opens up fine but the logIn window doesn't close. I need it so that the logIn window closes once the mainWindow is open. It doesn't matter if it does it before, during or after the mainWindow is open but as long as it does. I also need to be able to pass a value from the logInWindow to the mainWindow because of other parts of the program. I've made a simplified version of the code below.



    I tried using things such as QtWidgets.QDialog().close() (which were recognised by the code) but didn't actually do anything. The only thing that closed it was sys.exit() but that shut the whole thing down before the line code to open the mainWindow.



    #main.py
    import logInWindow

    var1 = input("Start: ")
    if var1 == 'y':
    logInWindow.openUp()


    #logInWindow.py
    from PyQt5 import QtCore, QtGui, QtWidgets
    import sys
    import mainWindow

    class Ui_Dialog(object):
    def setupUi(self, Dialog):
    Dialog.setObjectName("Dialog")
    Dialog.resize(400, 135)
    self.pushButton = QtWidgets.QPushButton(Dialog)
    self.pushButton.setGeometry(QtCore.QRect(110, 50, 161, 32))
    self.pushButton.setBaseSize(QtCore.QSize(161, 32))
    self.pushButton.setObjectName("pushButton")
    self.pushButton.clicked.connect(self.buttonClick)

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

    def buttonClick(self):
    #code to close logInWindow here
    needsToBePassed = 'This is the main window.'
    mainWindow.openUp2(needsToBePassed)

    def retranslateUi(self, Dialog):
    _translate = QtCore.QCoreApplication.translate
    Dialog.setWindowTitle(_translate("Dialog", "logInWindow"))
    self.pushButton.setText(_translate("Dialog", "open mainWindow"))

    def openUp():
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())


    #mainWindow.py
    from PyQt5 import QtCore, QtGui, QtWidgets
    import sys

    def openUp2(passed):
    class Ui_Dialog(object):
    def setupUi(self, Dialog):
    Dialog.setObjectName("Dialog")
    Dialog.resize(400, 300)
    self.label = QtWidgets.QLabel(Dialog)
    self.label.setGeometry(QtCore.QRect(110, 130, 151, 16))
    self.label.setObjectName("label")

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

    def retranslateUi(self, Dialog):
    _translate = QtCore.QCoreApplication.translate
    Dialog.setWindowTitle(_translate("Dialog", "mainWindow"))
    self.label.setText(_translate("Dialog", passed))

    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.exec_()


    If anyone could help me out that'd be great! Also if it's a few lines of code instead of changing how the code works, that'd be better but either would do.










    share|improve this question
























      0












      0








      0


      1






      I'm creating a program with PyQt5 and have made to .py files for two windows. One is a logIn window and the other is the mainWindow. To open the program a separate program, main.py, will call a subroutine in the logInWindow.py to open that window up. There is a button there that when clicked is supposed to close the logIn window and open up the mainWindow.py by calling it. The main window opens up fine but the logIn window doesn't close. I need it so that the logIn window closes once the mainWindow is open. It doesn't matter if it does it before, during or after the mainWindow is open but as long as it does. I also need to be able to pass a value from the logInWindow to the mainWindow because of other parts of the program. I've made a simplified version of the code below.



      I tried using things such as QtWidgets.QDialog().close() (which were recognised by the code) but didn't actually do anything. The only thing that closed it was sys.exit() but that shut the whole thing down before the line code to open the mainWindow.



      #main.py
      import logInWindow

      var1 = input("Start: ")
      if var1 == 'y':
      logInWindow.openUp()


      #logInWindow.py
      from PyQt5 import QtCore, QtGui, QtWidgets
      import sys
      import mainWindow

      class Ui_Dialog(object):
      def setupUi(self, Dialog):
      Dialog.setObjectName("Dialog")
      Dialog.resize(400, 135)
      self.pushButton = QtWidgets.QPushButton(Dialog)
      self.pushButton.setGeometry(QtCore.QRect(110, 50, 161, 32))
      self.pushButton.setBaseSize(QtCore.QSize(161, 32))
      self.pushButton.setObjectName("pushButton")
      self.pushButton.clicked.connect(self.buttonClick)

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

      def buttonClick(self):
      #code to close logInWindow here
      needsToBePassed = 'This is the main window.'
      mainWindow.openUp2(needsToBePassed)

      def retranslateUi(self, Dialog):
      _translate = QtCore.QCoreApplication.translate
      Dialog.setWindowTitle(_translate("Dialog", "logInWindow"))
      self.pushButton.setText(_translate("Dialog", "open mainWindow"))

      def openUp():
      import sys
      app = QtWidgets.QApplication(sys.argv)
      Dialog = QtWidgets.QDialog()
      ui = Ui_Dialog()
      ui.setupUi(Dialog)
      Dialog.show()
      sys.exit(app.exec_())


      #mainWindow.py
      from PyQt5 import QtCore, QtGui, QtWidgets
      import sys

      def openUp2(passed):
      class Ui_Dialog(object):
      def setupUi(self, Dialog):
      Dialog.setObjectName("Dialog")
      Dialog.resize(400, 300)
      self.label = QtWidgets.QLabel(Dialog)
      self.label.setGeometry(QtCore.QRect(110, 130, 151, 16))
      self.label.setObjectName("label")

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

      def retranslateUi(self, Dialog):
      _translate = QtCore.QCoreApplication.translate
      Dialog.setWindowTitle(_translate("Dialog", "mainWindow"))
      self.label.setText(_translate("Dialog", passed))

      Dialog = QtWidgets.QDialog()
      ui = Ui_Dialog()
      ui.setupUi(Dialog)
      Dialog.exec_()


      If anyone could help me out that'd be great! Also if it's a few lines of code instead of changing how the code works, that'd be better but either would do.










      share|improve this question














      I'm creating a program with PyQt5 and have made to .py files for two windows. One is a logIn window and the other is the mainWindow. To open the program a separate program, main.py, will call a subroutine in the logInWindow.py to open that window up. There is a button there that when clicked is supposed to close the logIn window and open up the mainWindow.py by calling it. The main window opens up fine but the logIn window doesn't close. I need it so that the logIn window closes once the mainWindow is open. It doesn't matter if it does it before, during or after the mainWindow is open but as long as it does. I also need to be able to pass a value from the logInWindow to the mainWindow because of other parts of the program. I've made a simplified version of the code below.



      I tried using things such as QtWidgets.QDialog().close() (which were recognised by the code) but didn't actually do anything. The only thing that closed it was sys.exit() but that shut the whole thing down before the line code to open the mainWindow.



      #main.py
      import logInWindow

      var1 = input("Start: ")
      if var1 == 'y':
      logInWindow.openUp()


      #logInWindow.py
      from PyQt5 import QtCore, QtGui, QtWidgets
      import sys
      import mainWindow

      class Ui_Dialog(object):
      def setupUi(self, Dialog):
      Dialog.setObjectName("Dialog")
      Dialog.resize(400, 135)
      self.pushButton = QtWidgets.QPushButton(Dialog)
      self.pushButton.setGeometry(QtCore.QRect(110, 50, 161, 32))
      self.pushButton.setBaseSize(QtCore.QSize(161, 32))
      self.pushButton.setObjectName("pushButton")
      self.pushButton.clicked.connect(self.buttonClick)

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

      def buttonClick(self):
      #code to close logInWindow here
      needsToBePassed = 'This is the main window.'
      mainWindow.openUp2(needsToBePassed)

      def retranslateUi(self, Dialog):
      _translate = QtCore.QCoreApplication.translate
      Dialog.setWindowTitle(_translate("Dialog", "logInWindow"))
      self.pushButton.setText(_translate("Dialog", "open mainWindow"))

      def openUp():
      import sys
      app = QtWidgets.QApplication(sys.argv)
      Dialog = QtWidgets.QDialog()
      ui = Ui_Dialog()
      ui.setupUi(Dialog)
      Dialog.show()
      sys.exit(app.exec_())


      #mainWindow.py
      from PyQt5 import QtCore, QtGui, QtWidgets
      import sys

      def openUp2(passed):
      class Ui_Dialog(object):
      def setupUi(self, Dialog):
      Dialog.setObjectName("Dialog")
      Dialog.resize(400, 300)
      self.label = QtWidgets.QLabel(Dialog)
      self.label.setGeometry(QtCore.QRect(110, 130, 151, 16))
      self.label.setObjectName("label")

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

      def retranslateUi(self, Dialog):
      _translate = QtCore.QCoreApplication.translate
      Dialog.setWindowTitle(_translate("Dialog", "mainWindow"))
      self.label.setText(_translate("Dialog", passed))

      Dialog = QtWidgets.QDialog()
      ui = Ui_Dialog()
      ui.setupUi(Dialog)
      Dialog.exec_()


      If anyone could help me out that'd be great! Also if it's a few lines of code instead of changing how the code works, that'd be better but either would do.







      python-3.x dialog pyqt5






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 9:14









      Matthew64Matthew64

      82 bronze badges




      82 bronze badges






















          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353425%2fhow-to-close-a-window-and-open-a-new-window-with-a-button-click%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353425%2fhow-to-close-a-window-and-open-a-new-window-with-a-button-click%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript