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. how to call Python file
Qt 6.11 is out! See what's new in the release blog

how to call Python file

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 412 Views
  • 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.
  • A Offline
    A Offline
    AvivY
    wrote on last edited by
    #1

    Hi to all,
    i have the following code:

    import sys
    from PyQt5.uic import loadUi
    from PyQt5 import QtWidgets
    from PyQt5.QtWidgets import QDialog, QApplication, QWidget
    
    import mit_main_dispay
    
    class LoginScreen(QDialog):
        def __init__(self):
            super(LoginScreen, self).__init__()
            loadUi("Style_Login_gui.ui", self)
            self.lineEdit_password.setEchoMode(QtWidgets.QLineEdit.Password)
            self.pushButton_login.clicked.connect(self.loginfunction)
    
        def loginfunction(self):
            username = self.lineEdit_username.text()
            password = self.lineEdit_password.text()
    
            if len(username) == 0 or len(password) == 0:
                self.label_massage.setText("Please input all fields.")
            else:
                if username == 'Aviv' and password == '1234':
                    print("Successfully logged in")
                    self.label_massage.setText("")
                    MIT_main_win = mit_main_dispay.MIT_main()
                    widget.addWidget(MIT_main_win)
                    widget.setCurrentIndex(widget.currentIndex() + 1)
                else:
                    self.label_massage.setText("Invalid username or password.")
    
    # main:
    app = QApplication(sys.argv)
    Login = LoginScreen()
    widget = QtWidgets.QStackedWidget()
    widget.addWidget(Login)
    widget.setFixedWidth(800)
    widget.setFixedHeight(920)
    widget.show()
    try:
        sys.exit(app.exec_())
    except:
        print("Exiting")
    

    in line 11 i want to call other file (my Login GUI) but i call to file that create by QT and not my update code (Style_Login_gui.py):

    # -*- coding: utf-8 -*-
    
    # Form implementation generated from reading ui file 'Style_Login_gui.ui'
    #
    # Created by: PyQt5 UI code generator 5.15.4
    #
    # 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
    import sys, res
    
    
    class Ui_Form(object):
        def setupUi(self, Form):
            Form.setObjectName("Form")
            Form.resize(625, 565)
            Form.setWindowFlag(QtCore.Qt.FramelessWindowHint)
            Form.setAttribute(QtCore.Qt.WA_TranslucentBackground)
            self.widget = QtWidgets.QWidget(Form)
            self.widget.setGeometry(QtCore.QRect(30, 30, 550, 500))
            self.widget.setStyleSheet("QPushButton#pushButton{\n"
                "    background-color: qlineargradient(spread:pad, x1:0, y1:0.505682, x2:1, y2:0.477, stop:0 rgba(11, 131, 120, 219), stop:1 rgba(85, 98, 112, 226));\n"
                "    color: rgba(255, 255, 255, 210);\n"
                "    border-radius: 5px;\n"
                "}\n"
                "\n"
                "QPushButton#pushButton:hover{\n"
                "    background-color: qlineargradient(spread:pad, x1:0, y1:0.505682, x2:1, y2:0.477, stop:0 rgba(150, 123, 111, 219), stop:1 rgba(85, 81, 84, 226));    \n"
                "}\n"
                "\n"
                "QPushButton#pushButton:pressed{\n"
                "    padding-left:5px;\n"
                "    padding-top:5px;\n"
                "    background-color:rgba(150, 123, 111,255);\n"
                "}\n"
                "\n"
                "\n"
                "\n"
                "")
            self.widget.setObjectName("widget")
            self.label = QtWidgets.QLabel(self.widget)
            self.label.setGeometry(QtCore.QRect(40, 30, 280, 430))
            self.label.setStyleSheet("border-image: url(C:/python_projects/MIT_project/Pics/best-Mac-wallpapers-apps.jpg);\n"
                "border-top-left-radius: 50px;\n"
                "\n"
                "")
            self.label.setText("")
            self.label.setObjectName("label")
            self.label_2 = QtWidgets.QLabel(self.widget)
            self.label_2.setGeometry(QtCore.QRect(270, 30, 240, 430))
            self.label_2.setStyleSheet("border-bottom-right-radius: 50px;\n"
                "background-color: rgba(255, 255, 255, 255);")
            self.label_2.setText("")
            self.label_2.setObjectName("label_2")
            self.label_3 = QtWidgets.QLabel(self.widget)
            self.label_3.setGeometry(QtCore.QRect(340, 80, 100, 40))
            font = QtGui.QFont()
            font.setPointSize(20)
            font.setBold(True)
            font.setWeight(75)
            self.label_3.setFont(font)
            self.label_3.setStyleSheet("color: rgba(0, 0, 0, 200);")
            self.label_3.setObjectName("label_3")
            self.lineEdit = QtWidgets.QLineEdit(self.widget)
            self.lineEdit.setGeometry(QtCore.QRect(295, 150, 190, 40))
            font = QtGui.QFont()
            font.setPointSize(10)
            self.lineEdit.setFont(font)
            self.lineEdit.setStyleSheet("background-color: rgba(0, 0, 0, 0);\n"
                "border:nane;\n"
                "border-bottom:2px solid rgba(46,82,101,200);\n"
                "color:rgba(0,0,0,240);\n"
                "padding-bottom:7px;")
            self.lineEdit.setObjectName("lineEdit")
            self.lineEdit_2 = QtWidgets.QLineEdit(self.widget)
            self.lineEdit_2.setGeometry(QtCore.QRect(295, 215, 190, 40))
            font = QtGui.QFont()
            font.setPointSize(10)
            self.lineEdit_2.setFont(font)
            self.lineEdit_2.setStyleSheet("background-color: rgba(0, 0, 0, 0);\n"
                "border:nane;\n"
                "border-bottom:2px solid rgba(46,82,101,200);\n"
                "color:rgba(0,0,0,240);\n"
                "padding-bottom:7px;")
            self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
            self.lineEdit_2.setObjectName("lineEdit_2")
            self.pushButton = QtWidgets.QPushButton(self.widget)
            self.pushButton.setGeometry(QtCore.QRect(295, 295, 190, 40))
            font = QtGui.QFont()
            font.setPointSize(11)
            font.setBold(True)
            font.setWeight(75)
            self.pushButton.setFont(font)
            self.pushButton.setStyleSheet("")
            self.pushButton.setObjectName("pushButton")
            self.label_4 = QtWidgets.QLabel(self.widget)
            self.label_4.setGeometry(QtCore.QRect(300, 340, 181, 31))
            self.label_4.setStyleSheet("color:rgba(0, 0, 0, 210);")
            self.label_4.setObjectName("label_4")
            self.label_5 = QtWidgets.QLabel(self.widget)
            self.label_5.setGeometry(QtCore.QRect(40, 90, 230, 130))
            self.label_5.setStyleSheet("background-color:rgba(0, 0, 0, 75);")
            self.label_5.setText("")
            self.label_5.setObjectName("label_5")
            self.label_6 = QtWidgets.QLabel(self.widget)
            self.label_6.setGeometry(QtCore.QRect(50, 80, 180, 40))
            font = QtGui.QFont()
            font.setPointSize(22)
            font.setBold(True)
            font.setWeight(75)
            self.label_6.setFont(font)
            self.label_6.setStyleSheet("color:rgba(255, 255, 255, 255);")
            self.label_6.setObjectName("label_6")
            self.label_7 = QtWidgets.QLabel(self.widget)
            self.label_7.setGeometry(QtCore.QRect(50, 145, 220, 50))
            font = QtGui.QFont()
            font.setPointSize(10)
            font.setBold(True)
            font.setWeight(75)
            self.label_7.setFont(font)
            self.label_7.setStyleSheet("color:rgba(255, 255, 255, 255);")
            self.label_7.setObjectName("label_7")
    
            self.retranslateUi(Form)
            QtCore.QMetaObject.connectSlotsByName(Form)
    
        def retranslateUi(self, Form):
            _translate = QtCore.QCoreApplication.translate
            Form.setWindowTitle(_translate("Form", "Form"))
            self.label_3.setText(_translate("Form", "Log In"))
            self.lineEdit.setPlaceholderText(_translate("Form", "User Name"))
            self.lineEdit_2.setPlaceholderText(_translate("Form", "Password"))
            self.pushButton.setText(_translate("Form", "L o g I n"))
            self.label_4.setText(_translate("Form", "Forgot your User Name or Password?"))
            self.label_6.setText(_translate("Form", "MIT APP"))
            self.label_7.setText(_translate("Form", "Hi, \n"
                "Welcome to FPGA team \n"
                "register tool."))
    
    if __name__ == "__main__":
        app = QtWidgets.QApplication(sys.argv)
        Form = QtWidgets.QWidget()
        ui = Ui_Form()
        ui.setupUi(Form)
        Form.show()
        sys.exit(app.exec_())
    
    

    what i miss?

    thanks.

    JonBJ 1 Reply Last reply
    0
    • A AvivY

      Hi to all,
      i have the following code:

      import sys
      from PyQt5.uic import loadUi
      from PyQt5 import QtWidgets
      from PyQt5.QtWidgets import QDialog, QApplication, QWidget
      
      import mit_main_dispay
      
      class LoginScreen(QDialog):
          def __init__(self):
              super(LoginScreen, self).__init__()
              loadUi("Style_Login_gui.ui", self)
              self.lineEdit_password.setEchoMode(QtWidgets.QLineEdit.Password)
              self.pushButton_login.clicked.connect(self.loginfunction)
      
          def loginfunction(self):
              username = self.lineEdit_username.text()
              password = self.lineEdit_password.text()
      
              if len(username) == 0 or len(password) == 0:
                  self.label_massage.setText("Please input all fields.")
              else:
                  if username == 'Aviv' and password == '1234':
                      print("Successfully logged in")
                      self.label_massage.setText("")
                      MIT_main_win = mit_main_dispay.MIT_main()
                      widget.addWidget(MIT_main_win)
                      widget.setCurrentIndex(widget.currentIndex() + 1)
                  else:
                      self.label_massage.setText("Invalid username or password.")
      
      # main:
      app = QApplication(sys.argv)
      Login = LoginScreen()
      widget = QtWidgets.QStackedWidget()
      widget.addWidget(Login)
      widget.setFixedWidth(800)
      widget.setFixedHeight(920)
      widget.show()
      try:
          sys.exit(app.exec_())
      except:
          print("Exiting")
      

      in line 11 i want to call other file (my Login GUI) but i call to file that create by QT and not my update code (Style_Login_gui.py):

      # -*- coding: utf-8 -*-
      
      # Form implementation generated from reading ui file 'Style_Login_gui.ui'
      #
      # Created by: PyQt5 UI code generator 5.15.4
      #
      # 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
      import sys, res
      
      
      class Ui_Form(object):
          def setupUi(self, Form):
              Form.setObjectName("Form")
              Form.resize(625, 565)
              Form.setWindowFlag(QtCore.Qt.FramelessWindowHint)
              Form.setAttribute(QtCore.Qt.WA_TranslucentBackground)
              self.widget = QtWidgets.QWidget(Form)
              self.widget.setGeometry(QtCore.QRect(30, 30, 550, 500))
              self.widget.setStyleSheet("QPushButton#pushButton{\n"
                  "    background-color: qlineargradient(spread:pad, x1:0, y1:0.505682, x2:1, y2:0.477, stop:0 rgba(11, 131, 120, 219), stop:1 rgba(85, 98, 112, 226));\n"
                  "    color: rgba(255, 255, 255, 210);\n"
                  "    border-radius: 5px;\n"
                  "}\n"
                  "\n"
                  "QPushButton#pushButton:hover{\n"
                  "    background-color: qlineargradient(spread:pad, x1:0, y1:0.505682, x2:1, y2:0.477, stop:0 rgba(150, 123, 111, 219), stop:1 rgba(85, 81, 84, 226));    \n"
                  "}\n"
                  "\n"
                  "QPushButton#pushButton:pressed{\n"
                  "    padding-left:5px;\n"
                  "    padding-top:5px;\n"
                  "    background-color:rgba(150, 123, 111,255);\n"
                  "}\n"
                  "\n"
                  "\n"
                  "\n"
                  "")
              self.widget.setObjectName("widget")
              self.label = QtWidgets.QLabel(self.widget)
              self.label.setGeometry(QtCore.QRect(40, 30, 280, 430))
              self.label.setStyleSheet("border-image: url(C:/python_projects/MIT_project/Pics/best-Mac-wallpapers-apps.jpg);\n"
                  "border-top-left-radius: 50px;\n"
                  "\n"
                  "")
              self.label.setText("")
              self.label.setObjectName("label")
              self.label_2 = QtWidgets.QLabel(self.widget)
              self.label_2.setGeometry(QtCore.QRect(270, 30, 240, 430))
              self.label_2.setStyleSheet("border-bottom-right-radius: 50px;\n"
                  "background-color: rgba(255, 255, 255, 255);")
              self.label_2.setText("")
              self.label_2.setObjectName("label_2")
              self.label_3 = QtWidgets.QLabel(self.widget)
              self.label_3.setGeometry(QtCore.QRect(340, 80, 100, 40))
              font = QtGui.QFont()
              font.setPointSize(20)
              font.setBold(True)
              font.setWeight(75)
              self.label_3.setFont(font)
              self.label_3.setStyleSheet("color: rgba(0, 0, 0, 200);")
              self.label_3.setObjectName("label_3")
              self.lineEdit = QtWidgets.QLineEdit(self.widget)
              self.lineEdit.setGeometry(QtCore.QRect(295, 150, 190, 40))
              font = QtGui.QFont()
              font.setPointSize(10)
              self.lineEdit.setFont(font)
              self.lineEdit.setStyleSheet("background-color: rgba(0, 0, 0, 0);\n"
                  "border:nane;\n"
                  "border-bottom:2px solid rgba(46,82,101,200);\n"
                  "color:rgba(0,0,0,240);\n"
                  "padding-bottom:7px;")
              self.lineEdit.setObjectName("lineEdit")
              self.lineEdit_2 = QtWidgets.QLineEdit(self.widget)
              self.lineEdit_2.setGeometry(QtCore.QRect(295, 215, 190, 40))
              font = QtGui.QFont()
              font.setPointSize(10)
              self.lineEdit_2.setFont(font)
              self.lineEdit_2.setStyleSheet("background-color: rgba(0, 0, 0, 0);\n"
                  "border:nane;\n"
                  "border-bottom:2px solid rgba(46,82,101,200);\n"
                  "color:rgba(0,0,0,240);\n"
                  "padding-bottom:7px;")
              self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
              self.lineEdit_2.setObjectName("lineEdit_2")
              self.pushButton = QtWidgets.QPushButton(self.widget)
              self.pushButton.setGeometry(QtCore.QRect(295, 295, 190, 40))
              font = QtGui.QFont()
              font.setPointSize(11)
              font.setBold(True)
              font.setWeight(75)
              self.pushButton.setFont(font)
              self.pushButton.setStyleSheet("")
              self.pushButton.setObjectName("pushButton")
              self.label_4 = QtWidgets.QLabel(self.widget)
              self.label_4.setGeometry(QtCore.QRect(300, 340, 181, 31))
              self.label_4.setStyleSheet("color:rgba(0, 0, 0, 210);")
              self.label_4.setObjectName("label_4")
              self.label_5 = QtWidgets.QLabel(self.widget)
              self.label_5.setGeometry(QtCore.QRect(40, 90, 230, 130))
              self.label_5.setStyleSheet("background-color:rgba(0, 0, 0, 75);")
              self.label_5.setText("")
              self.label_5.setObjectName("label_5")
              self.label_6 = QtWidgets.QLabel(self.widget)
              self.label_6.setGeometry(QtCore.QRect(50, 80, 180, 40))
              font = QtGui.QFont()
              font.setPointSize(22)
              font.setBold(True)
              font.setWeight(75)
              self.label_6.setFont(font)
              self.label_6.setStyleSheet("color:rgba(255, 255, 255, 255);")
              self.label_6.setObjectName("label_6")
              self.label_7 = QtWidgets.QLabel(self.widget)
              self.label_7.setGeometry(QtCore.QRect(50, 145, 220, 50))
              font = QtGui.QFont()
              font.setPointSize(10)
              font.setBold(True)
              font.setWeight(75)
              self.label_7.setFont(font)
              self.label_7.setStyleSheet("color:rgba(255, 255, 255, 255);")
              self.label_7.setObjectName("label_7")
      
              self.retranslateUi(Form)
              QtCore.QMetaObject.connectSlotsByName(Form)
      
          def retranslateUi(self, Form):
              _translate = QtCore.QCoreApplication.translate
              Form.setWindowTitle(_translate("Form", "Form"))
              self.label_3.setText(_translate("Form", "Log In"))
              self.lineEdit.setPlaceholderText(_translate("Form", "User Name"))
              self.lineEdit_2.setPlaceholderText(_translate("Form", "Password"))
              self.pushButton.setText(_translate("Form", "L o g I n"))
              self.label_4.setText(_translate("Form", "Forgot your User Name or Password?"))
              self.label_6.setText(_translate("Form", "MIT APP"))
              self.label_7.setText(_translate("Form", "Hi, \n"
                  "Welcome to FPGA team \n"
                  "register tool."))
      
      if __name__ == "__main__":
          app = QtWidgets.QApplication(sys.argv)
          Form = QtWidgets.QWidget()
          ui = Ui_Form()
          ui.setupUi(Form)
          Form.show()
          sys.exit(app.exec_())
      
      

      what i miss?

      thanks.

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

      @AvivY said in how to call Python file:

      in line 11 i want to call other file (my Login GUI) but i call to file that create by QT and not my update code (Style_Login_gui.py):

      What does this mean?

      You seem to have a dialog which you choose to show in a stacked widget. Slightly odd but I imagine it "works".

      A 1 Reply Last reply
      0
      • JonBJ JonB

        @AvivY said in how to call Python file:

        in line 11 i want to call other file (my Login GUI) but i call to file that create by QT and not my update code (Style_Login_gui.py):

        What does this mean?

        You seem to have a dialog which you choose to show in a stacked widget. Slightly odd but I imagine it "works".

        A Offline
        A Offline
        AvivY
        wrote on last edited by
        #3

        Hi @JonB,
        first thanks for your replay.

        what i means - line 11 work but it call to Style_Login_gui.ui and not to Style_Login_gui.py.

        what i need to write to call to Style_Login_gui.py?

        thanks.

        JonBJ 1 Reply Last reply
        0
        • A AvivY

          Hi @JonB,
          first thanks for your replay.

          what i means - line 11 work but it call to Style_Login_gui.ui and not to Style_Login_gui.py.

          what i need to write to call to Style_Login_gui.py?

          thanks.

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

          @AvivY
          Sorry, don't know what you mean. Neither a .ui nor a .py file can be "called".

          What is "line 11", of which file, anyway? And what does it do/not do that you want?

          1 Reply Last reply
          0

          • Login

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