Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. open new window in pyqt5
Forum Updated to NodeBB v4.3 + New Features

open new window in pyqt5

Scheduled Pinned Locked Moved Unsolved Qt for Python
9 Posts 6 Posters 14.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Samuel BachorikS Offline
    Samuel BachorikS Offline
    Samuel Bachorik
    wrote on last edited by
    #1
    This post is deleted!
    raven-worxR JonBJ 2 Replies Last reply
    0
    • Samuel BachorikS Samuel Bachorik

      This post is deleted!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Samuel-Bachorik
      i cant provide a python sample code.
      But basically a new window is shown for a widget without a parent or if it has a parent the widget's window flag property is set to Qt::Window.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • Samuel BachorikS Samuel Bachorik

        This post is deleted!

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Samuel-Bachorik
        connect() the first window's button clicked signal to a slot which calls secondWindow.show(). This is one of the most basic things you can do in a Qt UI.

        firstWindow.button.clicked.connect(secondWindow.show)
        
        1 Reply Last reply
        1
        • Samuel BachorikS Offline
          Samuel BachorikS Offline
          Samuel Bachorik
          wrote on last edited by Samuel Bachorik
          #4

          This is how my first windows looks like is it possible to connect it by your way @JonB
          And my second window looks same just changed few things.

          class MyWindow(QMainWindow):
          counter = 0
          score = 0
          test = 0

          def __init__(self):
              self.question_prompts = [
          
              ]
          
              self.score = 0
              self.counter = 0
              self.test = 0
              super(MyWindow, self).__init__()
              self.setGeometry(200, 200, 500, 300)
              self.setWindowTitle("Samko")
          
              self.label = QtWidgets.QLabel(self)
              self.label.move(20, 30)
              self.label.setText("Login system")
              self.update()
          
              self.label1 = QtWidgets.QLabel(self)
              self.label1.move(151, 50)
              self.label1.setText("Do you have account\ny/n ?")
              self.update2()
          
              self.b1 = QtWidgets.QPushButton(self)
              self.b1.setText("Enter")
              self.b1.move(149, 120)
              self.b1.resize(100, 32)
              self.b1.clicked.connect(self.clicked)
          
              self.textbox = QLineEdit(self)
              self.textbox.move(150, 90)
              self.textbox.resize(170, 28)
              self.textboxValue = self.textbox.text()
          
          
          
          
          def update(self):
              self.label.adjustSize()
          
          def update2(self):
              self.label1.adjustSize()
          

          def window():
          app = QApplication(sys.argv)
          win = MyWindow()
          win.show()
          sys.exit(app.exec_())

          window()

          JonBJ 1 Reply Last reply
          0
          • Samuel BachorikS Samuel Bachorik

            This is how my first windows looks like is it possible to connect it by your way @JonB
            And my second window looks same just changed few things.

            class MyWindow(QMainWindow):
            counter = 0
            score = 0
            test = 0

            def __init__(self):
                self.question_prompts = [
            
                ]
            
                self.score = 0
                self.counter = 0
                self.test = 0
                super(MyWindow, self).__init__()
                self.setGeometry(200, 200, 500, 300)
                self.setWindowTitle("Samko")
            
                self.label = QtWidgets.QLabel(self)
                self.label.move(20, 30)
                self.label.setText("Login system")
                self.update()
            
                self.label1 = QtWidgets.QLabel(self)
                self.label1.move(151, 50)
                self.label1.setText("Do you have account\ny/n ?")
                self.update2()
            
                self.b1 = QtWidgets.QPushButton(self)
                self.b1.setText("Enter")
                self.b1.move(149, 120)
                self.b1.resize(100, 32)
                self.b1.clicked.connect(self.clicked)
            
                self.textbox = QLineEdit(self)
                self.textbox.move(150, 90)
                self.textbox.resize(170, 28)
                self.textboxValue = self.textbox.text()
            
            
            
            
            def update(self):
                self.label.adjustSize()
            
            def update2(self):
                self.label1.adjustSize()
            

            def window():
            app = QApplication(sys.argv)
            win = MyWindow()
            win.show()
            sys.exit(app.exec_())

            window()

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Samuel-Bachorik said in open new window in pyqt5:

            self.b1.clicked.connect(self.clicked)

            That will make clicking the button connect to whatever the MyWindow.clicked method does. Where is that in your code? The method needs to show secondWindow, or just make it self.b1.clicked.connect(secondWindow.show), as I said.

            1 Reply Last reply
            2
            • Volodymyr14V Offline
              Volodymyr14V Offline
              Volodymyr14
              wrote on last edited by
              #6

              You can try subprocess to open your secondfile.py at the same time from the first window. :)

              PyQt/PySide

              1 Reply Last reply
              0
              • Samuel BachorikS Offline
                Samuel BachorikS Offline
                Samuel Bachorik
                wrote on last edited by
                #7

                Wow thank you man ! For your help ! My program is working now !! Thank you a lot !

                1 Reply Last reply
                0
                • Volodymyr14V Offline
                  Volodymyr14V Offline
                  Volodymyr14
                  wrote on last edited by
                  #8
                  class MainWindow(QWidget):
                  
                      def __init__(self, parent=None):
                          super(MainWindow, self).__init__(parent)
                  

                  PyQt/PySide

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bahadirio
                    wrote on last edited by
                    #9

                    Hello guys.

                    I have another but so close question. The main problem is all this tactics is not working on qtdesigner based .py files.

                    For examples:

                    f3c9596c-f9d3-4d03-9d30-cd9ee264463d-image.png

                    As you see there is just one buton. There is nothing more.

                    Just i wanted, when i push the button launch the same things.

                    This the first untouched code:

                    -- coding: utf-8 --

                    Form implementation generated from reading ui file 'x.ui'

                    Created by: PyQt5 UI code generator 5.15.2

                    WARNING: Any manual changes made to this file will be lost when pyuic5 is

                    run again. Do not edit this file unless you know what you are doing.

                    from PyQt5 import QtCore, QtGui, QtWidgets

                    class Ui_MainWindow(object):
                    def setupUi(self, MainWindow):
                    MainWindow.setObjectName("MainWindow")
                    MainWindow.resize(260, 226)
                    self.centralwidget = QtWidgets.QWidget(MainWindow)
                    self.centralwidget.setObjectName("centralwidget")
                    self.pushButton = QtWidgets.QPushButton(self.centralwidget)
                    self.pushButton.setGeometry(QtCore.QRect(90, 120, 75, 23))
                    self.pushButton.setObjectName("pushButton")
                    MainWindow.setCentralWidget(self.centralwidget)
                    self.menubar = QtWidgets.QMenuBar(MainWindow)
                    self.menubar.setGeometry(QtCore.QRect(0, 0, 260, 21))
                    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", "PushButton"))
                    

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

                    I just copied the class
                    7f8e0c3a-c900-4386-b617-6b5fe5432276-image.png

                    It's offer me build init 5c7ff758-d900-4c9d-b168-771fa5302c85-image.png

                    I aceepted
                    889c01b3-661a-4de3-bd7d-86b445cad839-image.png

                    Finally any solution didn't help me. Especially designer based codes hasn't solution.

                    from PyQt5 import QtCore, QtGui, QtWidgets

                    class Ui_MainWindow2(object):
                    def setupUi(self, MainWindow):
                    MainWindow.setObjectName("MainWindow")
                    MainWindow.resize(260, 226)
                    self.centralwidget = QtWidgets.QWidget(MainWindow)
                    self.centralwidget.setObjectName("centralwidget")
                    self.pushButton = QtWidgets.QPushButton(self.centralwidget)
                    self.pushButton.setGeometry(QtCore.QRect(90, 120, 75, 23))
                    self.pushButton.setObjectName("pushButton")
                    MainWindow.setCentralWidget(self.centralwidget)
                    self.menubar = QtWidgets.QMenuBar(MainWindow)
                    self.menubar.setGeometry(QtCore.QRect(0, 0, 260, 21))
                    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", "PushButton"))
                    

                    class Ui_MainWindow(object):
                    def init(self):
                    self.nextWindow = Ui_MainWindow2()

                    def setupUi(self, MainWindow):
                        MainWindow.setObjectName("MainWindow")
                        MainWindow.resize(260, 226)
                        self.centralwidget = QtWidgets.QWidget(MainWindow)
                        self.centralwidget.setObjectName("centralwidget")
                        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
                        self.pushButton.setGeometry(QtCore.QRect(90, 120, 75, 23))
                        self.pushButton.setObjectName("pushButton")
                        MainWindow.setCentralWidget(self.centralwidget)
                        self.menubar = QtWidgets.QMenuBar(MainWindow)
                        self.menubar.setGeometry(QtCore.QRect(0, 0, 260, 21))
                        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", "PushButton"))
                    
                        self.pushButton.clicked.connect(self.launcher)
                    
                    def launcher(self):
                        self.nextWindow.show()
                    

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

                    1 Reply Last reply
                    -1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved