gpt4 book ai didi

qlabel 中的 python 错误 : can not show . gif

转载 作者:太空宇宙 更新时间:2023-11-03 21:40:41 25 4
gpt4 key购买 nike

晚上好,我正在尝试通过按下按钮在 QLABEL 中生成动画,然后在该动画之后转到下一个窗口。

这是我正在做的事情的总结示例,因为在我的原始项目中,由于程序执行的过程,需要大约 5 秒的时间才能进入程序,所以我的意图是,当这段时间在 QLABEL 中运行动画时.

为此我使用此代码:

主程序.py

from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import uic
from FirebaseLogin import *
from contraInicio import ContraInicioC
#from Principal import PrincipalC
#from MostrarDatosTabla import mostararDatos
#from CrearFirebase import crear_tabla
#from sucursalInicio import sucursal
#import sqlite3

class LoginC(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
uic.loadUi("Interfaz/Login.ui",self)

self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.l_permiso.setAttribute(QtCore.Qt.WA_NoMousePropagation)
self.l_sucursal.setAttribute(QtCore.Qt.WA_NoMousePropagation)

self.l_close.clicked.connect(self.close)

self.contraseña = ContraInicioC()
#self.principal = PrincipalC()
self.l_entrar.clicked.connect(self.setDataPrincipal)
self.l_permiso.currentIndexChanged.connect(lambda:self.cambioPermiso(self.l_permiso.currentText()))
self.l_permiso.setCurrentText("Caja")
self.suc = "Exxe 1"
self.l_sucursal.setCurrentText(self.suc)
#self.principal.pc_fecha.setDate(QtCore.QDate.currentDate())



@QtCore.pyqtSlot(str)
def cambioPermiso(self,permiso):
if permiso == "Administrador":

self.l_sucursal.setEnabled(True)
else:

self.l_sucursal.setEnabled(False)

def setDataPrincipal(self):
movi = QtGui.QMovie("giphy.gif")
self.label.setMovie(movi)
movi.start()

self.estado = 0
fechaActual = QtCore.QDate.currentDate().toPyDate()

ref = db.reference("/"+str(fechaActual))
ret = ref.get()

if ret == None:

self.contraseña.show()
else:

self.contraseña.show()



self.close()

def mousePressEvent(self,event):

if event.button() == QtCore.Qt.LeftButton:
self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
event.accept()


def mouseMoveEvent(self,event):
if event.buttons() == QtCore.Qt.LeftButton:
self.move(event.globalPos() - self.dragPosition)
event.accept()

app = QApplication([])
l = LoginC()
l.show()
app.exec_()

contraInicio.py

from PyQt5.QtWidgets import QDialog, QApplication, QMessageBox
from PyQt5 import QtCore
from PyQt5 import uic
#from Contraseñas import passwordLogin
#from Principal import PrincipalC
#from MostrarDatosTabla import mostararDatos
#from CrearFirebase import crear_tabla


class ContraInicioC(QDialog):
def __init__(self):
QDialog.__init__(self)
uic.loadUi("Interfaz/Contraseña.ui",self)

self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

#self.principal = PrincipalC()
#boton de validación
self.validar.clicked.connect(self.validacion)
self.c1Close.clicked.connect(self.close)

self.permiso = None
self.turno = None
self.sucursal = None
self.estado = None
self.referencia = None


def validacion(self):
#self.datos(self.permiso,self.turno,self.sucursal,self.estado,self.referencia)
if self.password.text() == "esther":
print("ok")

else:
print("error")



def mousePressEvent(self,event):

if event.button() == QtCore.Qt.LeftButton:
self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
event.accept()


def mouseMoveEvent(self,event):
if event.buttons() == QtCore.Qt.LeftButton:
self.move(event.globalPos() - self.dragPosition)
event.accept()
#mostararDatos(str(QtCore.QDate.currentDate().toPyDate()),sucursal,turno,self.principal.saldo,self.principal.tablaM,self.principal.inventario,referencia)




#app = QApplication([])
#l = ContraInicioC()
#l.show()
#app.exec_()

登录.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>650</width>
<height>370</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="styleSheet">
<string notr="true">background:url(Imagenes/escalado.jpg);
background-position:center;
background-repeat:none;</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="l_close">
<property name="geometry">
<rect>
<x>620</x>
<y>0</y>
<width>31</width>
<height>23</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton#l_close{
background:none;
border:0px;
color:grey;
}
QPushButton#l_close:hover{
color:red;
}</string>
</property>
<property name="text">
<string>X</string>
</property>
</widget>
<widget class="QPushButton" name="l_entrar">
<property name="geometry">
<rect>
<x>550</x>
<y>330</y>
<width>75</width>
<height>22</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QPushButton#l_entrar{
background:#41CD52;
border:0px;
color:white;
}
QPushButton#l_entrar:pressed{
border-bottom:2px solid green;
}
</string>
</property>
<property name="text">
<string>Entrar</string>
</property>
</widget>
<widget class="QComboBox" name="l_sucursal">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>440</x>
<y>330</y>
<width>69</width>
<height>22</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QComboBox#l_sucursal{
background:none;
border:0px;
border-bottom: 1px solid lightblue;
color:#05839C;
}


QComboBox QAbstractItemView
{
border:0px;
background:white;
color: grey;

}
QComboBox#l_sucursal::drop-down
{
subcontrol-origin: padding;
subcontrol-position: top right;
width: 15px;
color: white;
border-left-width: 0px;
border-left-color: darkgray;
border-left-style: solid; /* just a single line */
border-top-right-radius: 3px; /* same radius as the QComboBox */
border-bottom-right-radius: 3px;
padding-left: 10px;
}</string>
</property>
<item>
<property name="text">
<string>Exxe 1</string>
</property>
</item>
<item>
<property name="text">
<string>Exxe 3</string>
</property>
</item>
</widget>
<widget class="QLabel" name="lsucursal">
<property name="geometry">
<rect>
<x>380</x>
<y>330</y>
<width>51</width>
<height>22</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color:grey;
background:none;</string>
</property>
<property name="text">
<string>Sucursal:</string>
</property>
</widget>
<widget class="QLabel" name="la">
<property name="geometry">
<rect>
<x>220</x>
<y>330</y>
<width>51</width>
<height>22</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color:grey;
background:none;</string>
</property>
<property name="text">
<string>Permisos</string>
</property>
</widget>
<widget class="QComboBox" name="l_permiso">
<property name="geometry">
<rect>
<x>268</x>
<y>330</y>
<width>91</width>
<height>22</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QComboBox#l_permiso{
background:none;
border:0px;
border-bottom: 1px solid lightblue;
color:#05839C;
}


QComboBox QAbstractItemView
{
border:0px;
background:white;
color: grey;

}
QComboBox#l_permiso::drop-down
{
subcontrol-origin: padding;
subcontrol-position: top right;
width: 15px;
color: white;
border-left-width: 0px;
border-left-color: darkgray;
border-left-style: solid; /* just a single line */
border-top-right-radius: 3px; /* same radius as the QComboBox */
border-bottom-right-radius: 3px;
padding-left: 10px;
}</string>
</property>
<item>
<property name="text">
<string>Administrador</string>
</property>
</item>
<item>
<property name="text">
<string>Caja</string>
</property>
</item>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>110</x>
<y>100</y>
<width>231</width>
<height>111</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>

Contraseña.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>302</width>
<height>156</height>
</rect>
</property>
<property name="windowTitle">
<string>Validación</string>
</property>
<property name="styleSheet">
<string notr="true">background:rgb(116, 116, 116);</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>80</x>
<y>20</y>
<width>141</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">color:white;</string>
</property>
<property name="text">
<string>Ingrese clave de acceso</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLineEdit" name="password">
<property name="geometry">
<rect>
<x>60</x>
<y>60</y>
<width>181</width>
<height>21</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background:none</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="validar">
<property name="geometry">
<rect>
<x>200</x>
<y>120</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QPushButton#validar{
background:rgb(56, 213, 47);
border:0px;
color:white;
}
QPushButton#validar:pressed{
border-bottom:2px solid green;
}</string>
</property>
<property name="text">
<string>Validar</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
<widget class="QFrame" name="frame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>311</width>
<height>16</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background:#0F5D8D;</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
<widget class="QPushButton" name="c1Close">
<property name="geometry">
<rect>
<x>286</x>
<y>0</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">color:white;
background:none;
border:0px;</string>
</property>
<property name="text">
<string>X</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

FirebaseLogin.py

import firebase_admin
from firebase_admin import credentials, db

cred = credentials.Certificate('login.json')
firebase_admin.initialize_app(cred,{
'databaseURL':'https://exe-tablas.firebaseio.com/'
})

enter image description here

最佳答案

由于问题不是 QMovie,问题是对 Firebase 的请求,这是一个阻塞任务,因此该任务必须在另一个线程中执行,因此我们避免阻止 GUI,阻止 gif 显示动画,创建一个允许将数据从辅助线程发送到主线程的信号,如下所示:

import threading
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from FirebaseLogin import db
from contraInicio import ContraInicioC


class LoginC(QtWidgets.QMainWindow):
firebaseFinished = QtCore.pyqtSignal(object)

def __init__(self, parent=None):
super(LoginC, self).__init__(parent)
uic.loadUi("Interfaz/Login.ui",self)

self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.l_permiso.setAttribute(QtCore.Qt.WA_NoMousePropagation)
self.l_sucursal.setAttribute(QtCore.Qt.WA_NoMousePropagation)
self.l_close.clicked.connect(self.close)
self.contraseña = ContraInicioC()
self.l_entrar.clicked.connect(self.setDataPrincipal)
self.l_permiso.currentIndexChanged.connect(self.cambioPermiso)
self.l_permiso.setCurrentText("Caja")
self.l_sucursal.setCurrentText("Exxe 1")
self.firebaseFinished.connect(self.on_firebaseFinished)

@QtCore.pyqtSlot()
def cambioPermiso(self):
self.l_sucursal.setEnabled(self.l_permiso.currentText() == "Administrador")

def setDataPrincipal(self):
movi = QtGui.QMovie("giphy.gif")
self.label.setMovie(movi)
movi.start()
fechaActual = QtCore.QDate.currentDate().toPyDate()
path = "/{}".format(fechaActual)
threading.Thread(target=self.get_data, args=(path,), daemon=True).start()

def get_data(self, path):
ref = db.reference(path)
ret = ref.get()
self.firebaseFinished.emit(ret)

def on_firebaseFinished(self, ret):
print("result", ret)
self.contraseña.show()
self.close()

def mousePressEvent(self,event):
if event.button() == QtCore.Qt.LeftButton:
self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
event.accept()

def mouseMoveEvent(self,event):
if event.buttons() == QtCore.Qt.LeftButton:
self.move(event.globalPos() - self.dragPosition)
event.accept()

if __name__ == '__main__':
import sys

app = QtWidgets.QApplication(sys.argv)
l = LoginC()
l.show()
sys.exit(app.exec_())

关于qlabel 中的 python 错误 : can not show . gif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52884600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com