如何在我的main.py(pyqt6)内打开ui_mainwindow文件

发布于 2025-02-02 20:51:01 字数 2201 浏览 2 评论 0原文

如何创建一个Main.py文件,它将访问子文件(屏幕,登录,注册)。

首先,它将打开登录屏幕,然后将打开主屏幕。

我在PYQT6中进行了整个项目,然后转换为PY文件。

我尝试在下面尝试做的方式,它只是给出了一个未定义的变量错误

from PySide6.QtCore import QCoreApplication
from PySide6.QtWidgets import (QApplication, QMainWindow)
from PyQt6.QtWidgets import QApplication, QMessageBox, QDialog, QMainWindow, QPushButton
from PyQt6.QtCore import QProcess
import os,sys,re,time,requests,pywhatkit,smtplib

from tela import Ui_MainWindow
from additem import Ui_MainWindowIsertBox
from login import Ui_MainWindowAcesso

#MAIN SCREEN CLASS
class telaprincipal(QMainWindow, Ui_MainWindow): #tela
    def __init__(self,*args,**argvs):
        super(telaprincipal,self).__init__(*args,**argvs)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.actionProduto.triggered.connect(self.add)

    def add(self):
        add = cadastrar()
        add.exec_()

#CLASS REGISTER ITEMS
class cadastrar(MainWindowIsertBox): #additem
    def __init__(self,*args,**argvs):
        super(cadastrar,self).__init__(*args,**argvs)
        self.ui = Ui_MainWindowIsertBox()
        self.ui.setupUi(self)

        
#CLASS FOR USER LOG IN
class login(MainWindowAcesso): #login
    def __init__(self,*args,**argvs):
        super(login,self).__init__(*args,**argvs)
        self.ui = Ui_MainWindowAcesso()
        self.ui.setupUi(self)
        self.ui.botao_confirmar_acesso.clicked.connext(self.login)

    def login(self):
        admin = "admin"
        senha = "admin"
        
        user = self.ui.label_inserir_user.text()
        passwd = self.ui.label_inserir_senha.text()
        
        if user == admin and passwd == senha:
            QMessageBox.information(QMessageBox(),"login realizado", "Logged")
            window = telaprincipal()
            window.show()
        else:
            QMessageBox.information(QMessageBox(),"login não realizado", "Logged Failed")


#application
if __name__ == "__main__":
    enter image description here
    app = QApplication(sys.argv)
    Window = login()
    Window.show()
    sys.exit(app.exec())

script

how do I create a main.py file, where it will access the child files (screen, login, registration).

first it will open the login screen, and then it will open the main screen.

I made the whole project in pyqt6, and converted to py file.

The way I tried to do it below, it just gives an undefined variable error

from PySide6.QtCore import QCoreApplication
from PySide6.QtWidgets import (QApplication, QMainWindow)
from PyQt6.QtWidgets import QApplication, QMessageBox, QDialog, QMainWindow, QPushButton
from PyQt6.QtCore import QProcess
import os,sys,re,time,requests,pywhatkit,smtplib

from tela import Ui_MainWindow
from additem import Ui_MainWindowIsertBox
from login import Ui_MainWindowAcesso

#MAIN SCREEN CLASS
class telaprincipal(QMainWindow, Ui_MainWindow): #tela
    def __init__(self,*args,**argvs):
        super(telaprincipal,self).__init__(*args,**argvs)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.actionProduto.triggered.connect(self.add)

    def add(self):
        add = cadastrar()
        add.exec_()

#CLASS REGISTER ITEMS
class cadastrar(MainWindowIsertBox): #additem
    def __init__(self,*args,**argvs):
        super(cadastrar,self).__init__(*args,**argvs)
        self.ui = Ui_MainWindowIsertBox()
        self.ui.setupUi(self)

        
#CLASS FOR USER LOG IN
class login(MainWindowAcesso): #login
    def __init__(self,*args,**argvs):
        super(login,self).__init__(*args,**argvs)
        self.ui = Ui_MainWindowAcesso()
        self.ui.setupUi(self)
        self.ui.botao_confirmar_acesso.clicked.connext(self.login)

    def login(self):
        admin = "admin"
        senha = "admin"
        
        user = self.ui.label_inserir_user.text()
        passwd = self.ui.label_inserir_senha.text()
        
        if user == admin and passwd == senha:
            QMessageBox.information(QMessageBox(),"login realizado", "Logged")
            window = telaprincipal()
            window.show()
        else:
            QMessageBox.information(QMessageBox(),"login não realizado", "Logged Failed")


#application
if __name__ == "__main__":
    enter image description here
    app = QApplication(sys.argv)
    Window = login()
    Window.show()
    sys.exit(app.exec())

script

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め可乐爱微笑 2025-02-09 20:51:02

我要走的方式是,我将创建的.UI文件直接加载到主文件中(跳过.UI到.py部分的转换)

请参阅下面的代码以获取参考:

class Ui(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui, self).__init__()
        uic.loadUi('get_input.ui', self)
        self.setWindowTitle("Game")
        self.pushButton.pressed.connect(self.save)
        self.show()

    def save(self):
        self.algorithm = self.comboBox.currentText()
        self.close()

这里我创建了一个名为<的UI文件代码> get_input.ui ,然后直接加载到代码上,然后通过从中获得一些输入来进行交互。这种方式要容易得多。

The way I'd go is that I'd load the .ui files I created into my main file directly (skiping the convertion from .ui to .py part)

See below code for reference:

class Ui(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui, self).__init__()
        uic.loadUi('get_input.ui', self)
        self.setWindowTitle("Game")
        self.pushButton.pressed.connect(self.save)
        self.show()

    def save(self):
        self.algorithm = self.comboBox.currentText()
        self.close()

Here I have created a ui file called get_input.ui and I load directly onto my code then I interacted with it by getting some input from it. It's much easier this way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文