如何在我的main.py(pyqt6)内打开ui_mainwindow文件
如何创建一个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())
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())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我要走的方式是,我将创建的.UI文件直接加载到主文件中(跳过.UI到.py部分的转换)
请参阅下面的代码以获取参考:
这里我创建了一个名为<的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:
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.