GIF не отображается в окне PyQt5Python

Программы на Python
Ответить
Anonymous
 GIF не отображается в окне PyQt5

Сообщение Anonymous »

Это код, который я написал. Проблема, с которой я столкнулся, заключается в том, что GIF-файл, который я хочу отобразить, не отображается. Я предполагаю, что я добавил поверх него еще один слой, но не знаю, как это исправить.

Код: Выделить всё

from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit, QStackedWidget, QWidget, QLineEdit, QGridLayout, QVBoxLayout, QHBoxLayout, QPushButton, QFrame, QLabel, QSizePolicy
from PyQt5.QtGui import QIcon, QPainter, QMovie, QColor, QTextCharFormat, QFont, QTextBlockFormat, QPixmap
from PyQt5.QtCore import Qt, QSize, QTimer
from dotenv import dotenv_values
import sys
import os

env_vars=dotenv_values(".env")
Assistantname = env_vars.get("Assistantname")
current_dir = os.getcwd()
old_chat_message = ""
TempDirPath = rf"{current_dir}\Frontend\Files"
GraphicsDirPath=rf"{current_dir}\Frontend\Graphics"

def AnswerModifier(Answer):
lines = Answer.split('\n')
non_empty_lines = [line for line in lines if lines.strip()]
modified_answer = '\n'.join(non_empty_lines)
return modified_answer

def QueryModifier(Query):
new_query = Query.lower().strip()
query_words = new_query.split()
question_words = ["how", "what", "who", "where", "when", "why", "which", "whose", "whom", "can you", "what's", "where's", "how's", "can you"]

if any(word + " "  in new_query for word in question_words):
if query_words[-1][-1] in ['.','?','!']:
new_query = new_query[:-1] + "?"
else:
new_query += "?"
else:
if query_words[-1][-1] in ['.','?','!']:
new_query = new_query[:-1] + "."
else:
new_query += "."
return new_query.capitalize()

def SetMicrophoneStatus(Command):
with open(rf'{TempDirPath}\Mic.data', "w", encoding='utf-8') as file:
file.write(Command)

def GetMicrophoneStatus(Command):
with open(rf'{TempDirPath}\Mic.data', "r", encoding='utf-8') as file:
Status = file.read(Command)
return Status

def SetMicrophoneStatus(Command):
with open(rf'{TempDirPath}\Mic.data', "w", encoding='utf-8') as file:
file.write(Command)

def SetMicrophoneStatus(Command):
with open(rf'{TempDirPath}\Mic.data', "r", encoding='utf-8') as file:
Status = file.read(Command)
return Status

def MicButtonInitialed():
SetMicrophoneStatus("False")

def MicButtonClosed():
SetMicrophoneStatus("True")

def GraphicsDirectoryPath(Filename):
Path = rf'{GraphicsDirPath}\{Filename}'
return Path

def TempDirectoryPath(Filename):
Path = rf'{TempDirPath}\{Filename}'
return Path

def ShowTextToScreen(Text):
with open(rf'{TempDirPath}\Responses.data', "w", encoding='utf-8') as file:
file.write(Text)

class ChatSection(QWidget):

def __init__(self):
super(ChatSection, self).__init__()
layout = QVBoxLayout(self)
layout.setContentsMargins(-10,40,40,100)
layout.setSpacing(-100)
self.chat_text_edit = QTextEdit()
self.chat_text_edit.setReadOnly(True)
self.chat_text_edit.setTextInteractionFlags(Qt.NoTextInteraction)
self.chat_text_edit.setFrameStyle(QFrame.NoFrame)
layout.addWidget(self.chat_text_edit)
self.setStyleSheet("background-color: black;")
layout.setSizeConstraint(QVBoxLayout.SetDefaultConstraint)
layout.setStretch(1, 1)
self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
text_color= QColor(Qt.blue)
text_color_text = QTextCharFormat()
text_color_text.setForeground(text_color)
self.chat_text_edit.setCurrentCharFormat(text_color_text)
self.gif_label = QLabel()
self.gif_label.setStyleSheet("border: none;")
movie = QMovie(GraphicsDirectoryPath('Jarvis.gif'))
max_gif_size_W = 480
max_gif_size_H = 270
movie.setScaledSize(QSize(max_gif_size_W, max_gif_size_H))
self.gif_label.setAlignment(Qt.AlignRight | Qt.AlignBottom)
self.gif_label.setMovie(movie)
movie.start()
layout.addWidget(self.gif_label)
self.label = QLabel("")
self.label.setStyleSheet("color: white; font-size:16px; margin-right: 195px; border: none;  margin-top: -30px;")
self.label.setAlignment(Qt.AlignRight)
layout.addWidget(self.label)
layout.setSpacing(-10)
layout.addWidget(self.gif_label)
font = QFont()
font.setPointSize(13)
self.chat_text_edit.setFont(font)
self.timer = QTimer(self)
self.timer.timeout.connect(self.loadMessages)
self.timer.timeout.connect(self.SpeechRecogText)
self.timer.start(5)
self.chat_text_edit.viewport().installEventFilter(self)
self.setStyleSheet("""
QScrollBar:vertical {
border: none;
background: black;
width: 10px;
margin: 0px 0px 0px 0px;
}

QScrollBar::handle:vertical {
background: white;
min-height: 20px;
}

QScrollBar::add-line:vertical {
background: black;
subcontrol-position: bottom;
subcontrol-origin: margin;
height: 10px;
}

QScrollBar::sub-line:vertical {
background: black;
subcontrol-position: top;
subcontrol-origin: margin;
height: 10px;
}

QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
border: none;
background: none;
color: none;
}

QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
background:  none;
}
""")

def loadMessages(self):
global old_chat_message
with open(TempDirectoryPath('Responses.data'), "r", encoding='utf-8') as file:
messages = file.read()

if None==messages:
pass
elif len(messages)

Подробнее здесь: [url]https://stackoverflow.com/questions/79345134/gif-not-displaying-in-pyqt5-window[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»